MacOS architecture

Jamie
6 min readJan 14, 2022

--

You have to understand your operating system to automate things in it or to just have a better understanding how mac os works. The whole OS is to big to explain in just one story but I want you to have a ruff overview and understandig of the structure.

In this story i dont what to talk about Darwin, Cocoa or Aqua but this image is for the people who are interestet in the exact processes on developer base. First it have to be clear how the OS is build. In addition to that i want to talk about the File System, Terminal, CoreServices and much more.

Shift + command +G

/System/Library/CoreServices

The System folder on MacOSX is a complex thing. You not allowed to write in the System Folder so you are really restricted with the things you can do. I often hit this border when i want to costemize my os. That means there a sometimes problems with the permissions but I am also looking for a way to bypass this problem.

But thats not the point now first i want to dive deeper in to the MacOS file system. But only one more thing before we start

Shift + command + .

You will often need this when you work with your System folder on Mac. You can use this command to show & hide hidden folders and files.

MacOS in general

The operating System MacOS is based on the Darwin Kernel what is UNIX like, since 2007 thats a big plus point why many developers love it. In this Story I will only explain how different file systems work together with applications but the whole OS goes a lot deeper. The Core OS of MacOS is Darwin. Darwin is the Base of the hole Apple OS like you know it now. Its open Source but the last downloadable version has not updated for a long time. Darwin is a OS with no GUI “Grafical User Interface”. You can still download the Kernel on GitHub or a community project like PureDarwin.

The file system

The file system of MacOS is root based like on Linux that means the top of the folder branching for normal use is the User folder. When you familiar with the Linux folder structure and right structure you will understand the apple structure immediately. You have the same things like root rights and the home folder. The home folder is the start point when you change directory via terminal. But on Linux everything is “Open Source“ and thats the difference to MacOS. The whole System folder is only readable for the user. Only in the hidden Library folder you can change data for applications like your VS Code extensions folder which is also located there.

To describe it a bit more, the root of the folder tree is your home order. From there you can access the other twigs like your Desktop folder and so on. When you want to understand it it is a really good comparison to think about it like a tree.

CoreServices

Basic Applications that run in the background

Do you ever thougt about how the dock on your Mac works. Like is it a application or is it programmed some where in the depths of the System folder. And yes actually both things are right but its not really in the depths. You can find it following the next path. I recommend you to use your “Go to folder” Shortcut by just pressing: Shift + command +G like I wrote earlier. Or use your terminal but I prefer the finder because we will also work with images.

/System/Library/CoreServices

When I opened this folder the first time I was like oh my god this is also located here wow. My biggest attention received the Dock.app because I lately wrote a script to automatically add my basic apps to the the dock. I right clicked the app and pressed “Show Package Contents”. This is also a good tipp for you when you want to understand how applications interact with the os and were the icon is located for example. Anyways in the source folder I looked for the notification circle because I wanted to change the color of it.

/System/Library/CoreServices/Dock.app/Contents/Resources/statuslabel.png

This is the whole path or just click through it when you are already in the “Contents” folder. Just look through the “Resources” folder and you will find all the images your dock needs and yes it is a application like every other app on your computer but you dont know it.

Automations for the Dock

I recently said I automated the process of moving applications to my Dock and now i want to show you how I did. I dont know if you are familiar with writing shell scripts but thats not really importend because we will only change some things in the plist — Property List of com.apple.dock(.plist)

com.apple.dock — /System/Library/Preferences/

This is the path to one of these files but you cant do much with it, it is just a side note. What you can see there is that it is a XPC Service. If you want more informations about that just click on the following link

But back to our main topic. With the following command you can add things to your dock

defaults write com.apple.dock persistent-apps -array-add ‘<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/Applications/Safari.app</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>’

I my case it would add Safari to the Dock but only when the app is already in the applications folder. When you run this in your Terminal you will notice nothing happens thats because you have to refresh your dock by typing

killall Dock

But thats not what we want! You could use this command for every single app that you want to add but to automate this you will need a shell script. You can create a shell script for example in vs code or create one with your terminal and edit it there or in TextEdit. When you want to use your terminal type touch test.sh and it will create this file in your user folder. For test you can use every name you like. Now open the file with text edit by right clicking it.

No matter which method you choosed the first line of your script has to be

#!/bin/sh

Than just use the same command like you recently used in your command line. You can use write com.apple.dock as often as you like and only have to use the killall command ones on the end. To run a sh file type the following on your terminal when you are done

sh path/to/file

or make it execute able with the following command to just double click it

chmod +x path/to/file

I wrote to scripts but you can use what you learned for what ever you like

  1. Add specific apps to my dock
  2. Remove these applications from the dock again

To remove the apps from the dock again you have to write a new script and fill it with one command. The following link shows a little bit how you do it and there is a download link.

That was only one example for how you can use a CoreService like the Dock.app but you can explore the functions of every other app and find ways for you to use it for your benefits.

When you interested in the deeper functions of MacOS are more detailed and professional story will follow.

--

--