Automate Mac environment construction!


Automate Mac environment construction!

I want to cut corners by building an environment on a new Mac!

I need to set up a new Mac because I joined the company, I want to do a clean installation to clean the inside of the Mac, I want to install the beta version of MacOS on another volume in the Mac at this time, I think that there are times when you want to build a Mac environment.

When you buy a Mac for the first time, you will probably set it from scratch and install various apps and tools, but from the second time onward, it is quite difficult to manually reconfigure the ones you built one by one.

Therefore, let’s set the automation so that you can save labor by automatically executing the apps and tools to be installed in advance and the settings you use every day!

Here, I will introduce the settings I am using. If you want to set up automation yourself, it’s a good idea to base it on and customize it to suit your environment!
(Since I’ve been adding it little by little since long ago, I think it’s difficult to understand how to write it, it’s not correct, and there may be some errors depending on the environment, so please correct it as appropriate!)

Learn how to set up a repository for Mac setup

The corresponding repository is listed first.

For the first setting, execute the following code in order as described in the README.

# ①
sudo curl -fsSL | sh
# ②
cd ./mac-setup
# ③
make setup

For process (1), from the above repository and execute it.
In this process, (1) install Homebrew, (2) install git, and (3) clone the above repository.

In process (2), move the directory to mac-setup, and in process (3), set up various things. Detailed processing is described in this file, but specifically, do the following.
(1) Installation of tools and apps described in Brewfile
(2) Personal and work repositories, personal settings and license files, clones of libraries including Credentials, initial settings (in this repository, it is written as SettingFiles)
(3) zsh settings
(4) Change the save destination of Mac capture
(5) Settings of various development tools such as flutter / node / terminal / ruby

The point of this time is to store the clone of the repository and various settings / license files that you do not want to make public in (2), in my case Alfred, BetterTouchTool, VSCode setting file, Xcode key binding file, etc.
If someone else runs this mac-setup as it is, you will be asked for the password for this personal repository, so change it!

For (1), you can check the details at the following site

Detailed explanations on (3) to (5) are omitted here.

If you are interested, please take a look at the actual code.

Other features

In addition to automating environment construction, this mac-setup and SettingFiles repository includes the following functions and settings.

(1) Alias and environment variables of Git and various tools

The alias of the command of git and various tools used in terminal is registered.
Details will be published in a separate article.

(2)Convenient function

I don’t use it every day, but I think there are some tasks that I do occasionally, but sometimes I find it annoying.

For such things, once you write the process, you only need to execute the process from the second time onward!
For example, the replaceKeybindingFile function implemented here.
In Xcode, I make it possible to copy a custom shortcut by myself, for example, in my case, Shift + Option + ↓ to copy the corresponding code below like VSCode, but to apply it to Xcode, create a file called IDETextKeyBindingSet.plist, and it must be placed in the specified path.
This has to be done every time you download a new Xcode, but it’s quite difficult to copy it by following the path in the Finder.

However, if you use this function, just specify the Xcode version as an argument, like replaceKeybindingFile 12.5, and the file stored in SettingFiles will be copied to the specified location.
Alias is also provided, so you can write it as rkb 12.5.

It’s easy because once you define a function like this, all you have to do is execute it!

In this repository, if you add a new alias, environment variable, or function, you can immediately call it from Terminal by executing sz (source ~ / .zshrc).


To make it easier to automate the Mac environment construction, it is recommended to save all the data in the Mac to the cloud so that it can be downloaded from any device.
In my case, not only application projects but also various license files and other files are managed in the Github repository. Other data is also stored in the basic iClould and Google Drive.
If you have data locally on your Mac, you’ll have to move it to a new environment individually, which can be quite a hassle.
If there are large files such as design files and video files that are difficult to upload to the cloud, it is a good idea to use external storage to make it easier to migrate the data!

Wrapping up

This time, I have summarized the repository that I use to automate the environment construction of Mac.
The initial construction is difficult, but after that you can easily execute it by simply calling the corresponding process.
It is difficult to put all the processes together suddenly, so I think it’s a good idea to start small and add processes little by little.
If you are an engineer, it is troublesome, and if you want to do the same processing, you will want to standardize it, but by summarizing such Mac environment construction and daily work in scripts and settings , Main work and development work will be much easier, so if you haven’t set it yet, let’s go!



Your email address will not be published. Required fields are marked *