Questions and Confusions for Mac Beginners
Tags: mac
Published: 2024-03-06 13:11:26

## Preface

Switched to an M2 MacBook, as a long-term Windows user, I have encountered many problems and confusions up to now. Some have been solved, while others have not yet found a solution. Here, I record and share them.

## System

### How to Add Fonts

Previously, my daily font was [Sarasa Gothic](https://github.com/be5invis/Sarasa-Gothic), which is not outstanding, but its main advantage is supporting Simplified and Traditional Chinese, Japanese, and English in a unified style.
The basic steps are similar to Windows: download the ttc file, click to open it, and wait for the verification to pass. However, this process is very slow on a Mac, so slow that I thought there was a bug.

### How to Keep the Mac Awake with the Lid Closed When Connected to an External Display

Although I found a bunch of answers, it turns out that all you need to do is connect to power and set the external monitor as the primary display.

> There is still a bug, sometimes I cannot wake it up using an external keyboard and mouse.

### How to Reverse Mouse Scrolling Direction

This was one of the very first things I was not used to, but it can be adjusted by using a tool called [SCROLL REVERSER](https://pilotmoon.com/scrollreverser/) to set it to reverse.

### Checking for Global Shortcut Key Conflicts on Mac

I haven't found a truly viable solution, so I will continue to search for Mac's shortcut key settings through Google and asking questions.

### How to Use Other Input Methods

Simply download the system's input methods, then you can switch input methods using `ctrl+space`.

> Since it conflicts with the shortcut key for suggestions in vscode, I changed it to `ctrl+shift+space`.

### Using Function Keys on Mac Without Pressing Fn

Enable **Use F1, F2, etc. keys as standard function keys** in system preferences, ref: <https://support.apple.com/102439>
![1675933558696.png](https://i.ibb.co/rypBXv2/image.png)

> I found that the shortcut key for refreshing the browser page, F5, does not work...

### How to Hide from Dock When Closing the Main Window of an App

This depends on whether the app supports this behavior, for example, SSR supports minimizing to the top right corner after closing the window, but Proxifier does not support it and must occupy a place in the dock.

### How to List and Switch Between All Windows

Mac's command+tab can only switch applications, but not multiple windows within the same application.
To switch between multiple windows of the same application, use the command+\~ shortcut.
To list all windows, you can use the ctrl+top shortcut, but it's not possible to switch using a shortcut, moving the right hand from the mouse to the keyboard and back to the mouse is too counterintuitive, and the sizes being different is strange.

Using [alt-tab](https://github.com/lwouis/alt-tab-macos) can restore behavior similar to Windows.
![6a9735ba560f48bb913d8fed5171aa17.jpg](https://blog.rxliuli.com/resources/00a366fbbbd74ed3825afbb176dff465.jpg)

### Disabling Right-Click Menu in Chrome

By default, Chrome displays several integrated right-click menu items for Mac, which are not practical most of the time and need to be disabled.
![1676515401808.png](https://i.ibb.co/fDHG6pR/image.png)
Well, it seems this issue is unsolvable, which is really unfortunate. ref: <https://superuser.com/questions/1012292/>

### Changing Cursor Movement Shortcuts to Windows Style in Input

The cursor movement shortcuts on Mac might be good, but there is obviously a significant difference from Windows.
In Windows, the following keys are generally used to move the cursor:

- Home/End to jump to the beginning/end of the line
- Ctrl+Home/End to jump to the beginning/end of the text
- Ctrl+Left/Right to jump to the beginning/end of the word

All the above keys can be used in combination with Shift.

This issue can be mitigated by configuring global keyboard mapping with [Karabiner-Elements](https://karabiner-elements.pqrs.org/).
![1676608991086.png](https://blog.rxliuli.com/resources/8fea00bb34c743939d69be7272208488.png)

### How to Download DMG Files from Third Parties

Not addressed yet

### How to Kill a Specific Process

Sometimes a background program freezes and needs to be restarted, but Activity Monitor seems unable to right-click to kill a process.
Use the Linux commands ps + kill -9

***

In Activity Monitor, first select the process you want to kill, then click the ⊗ in the navigation bar.
![1677041471659.png](https://i.ibb.co/NT07pdc/image.png)

### Disabling Cmd+Shift+A Triggering "No manual entry for setting;type=a" on Mac

In JetBrains' IDEs, Cmd+Shift+A triggers "No manual entry for setting;type=a," another example of Mac's "helpful" shortcuts.
![1679969498468.png](https://i.ibb.co/fQQymx1/image.png)

This can be resolved by:

1. Opening **System Preferences => Keyboard => Shortcuts => Services**
2. Disabling **Text => Search man Page Index in Terminal**

![1679969667352.png](https://i.ibb.co/kJS91R0/image.png)

### Automatically Close Notifications in the Top Right Corner

Sometimes the system pops up notifications, such as software updates, but these notifications will stay visible in the top right corner indefinitely unless actively closed, which is very annoying. I would prefer them to automatically hide like in Windows and be viewable in the notification list if needed.

Tools like Automator seem to only set shortcuts for closing notifications and cannot automatically close system notifications after a few seconds.

### Set Gmail Web Version as the Default System Mail Client

The built-in mail client on Mac might be useful, but having gotten used to Gmail, I want to set Gmail as the default system mail client. This process is much more complicated than on Windows, refer to the tutorial: <https://support.apple.com/102362>

### How to Synchronize Files to a Phone via USB Differentially

The actual need is to synchronize the OneDrive and the e-book reader's directory. Surprisingly, when connecting an Android phone to a Mac, files cannot be transferred directly through Finder. It requires Google's [Android File Transfer](https://www.android.com/filetransfer/) program, which does not support differential sync.

> This helps understand why some people dislike Mac, saying it's too closed, as its support for non-Apple products is quite poor.

### Disable the Mouse Move to Bottom Right Corner to Show Notes

1. Open **System Preferences => Search "Hot Corners" => Hot Corners**
2. Remove the note trigger in the bottom right corner.

![1681267609807.png](https://i.ibb.co/zxnKb62/image.png)

## Finder

### Deleting Icons from the Desktop in Mac

Use Command+Delete to delete the selected icon.

### Quick Switch Between Windows

Using Ctrl+Left/Right can switch between adjacent windows, which is very useful for quickly accessing commonly used windows during development. (Restores the old behavior similar to multiple windows, abandoning the mobile-like practice of one app covering the screen)

### Display Hidden Files

`Command+Shift+.` can temporarily toggle the display of hidden files.

Use the following method for a permanent setting (seems not to work for file selectors triggered by browsers):

```sh
defaults write com.apple.finder AppleShowAllFiles -bool true # Show hidden files
defaults write com.apple.finder AppleShowAllFiles -bool false # Hide hidden files
killall Finder # Restart Finder
```

![1676374613271.png](https://i.ibb.co/D82cqdF/image.png)

### How to Paste a File Path

Sometimes, after copying a file path, you may want to quickly open it in Finder. You can use the `Command+Shift+G` shortcut, then paste the path.

![1676374734148.png](https://i.ibb.co/WH7ryKS/image.png)

### Open Terminal or VSCode in the Current Directory

After selecting a directory, go to **Finder => Services => New iTerm2 Window Here** to open it.

![1676352594802.png](https://i.ibb.co/HVDH3kR/image.png)

> This is actually different from what was expected to open the current directory and is also relatively slow.

Well, it's actually also available in the right-click context menu's submenu.

![1676366846045.png](https://i.ibb.co/dBrJ3D0/image.png)

Opening iTerm2 for the first time will have two terminals, which appears to be a bug.

***

You can use [szContext](https://github.com/RoadToDream/SzContext) to customize the context menu.

### Changing the Default Program for Opening a File

1. In Finder, right-click on a file of the type you wish to change, to bring up the context menu.
2. In the menu, select the "Get Info" option.
3. In the dialog that appears, expand the "Open With" option.
4. Choose the program you want to set as the default for opening this type of file, and click on "Change All..." below.

![1676366713119.png](https://i.ibb.co/W2ptjC2/image.png)

Selecting the **Always Open With** option when opening an application is confusing; it turns out it only applies to that specific file.
![1676612397276.png](https://i.ibb.co/QXqHjw1/image.png)

A better tool for this is duti, which can get or set the default program for a specific file type. This is particularly useful for batch changing the default application from Xcode to Visual Studio Code for opening certain file types.

```sh
# https://github.com/moretension/duti
brew install duti
# from https://github.com/vscode-icons/vscode-icons/blob/74220b6f8389ad5c5d9f68b2029d91460de2b374/src/iconsManifest/languages.ts#L319
filetypes=(.as .ada .prw .affect .al .ansible .g4 .any .htaccess .cls .apib .apl .applescript .adoc .asp .asm .ats .ahk .au3 .avcs .azcli .azure-pipelines.yml .bal .bat .bats .bzl .bf .bicep .bib .biml .blade.php .blitzbasic .bolt .bsq .buf.yaml .c .cal .cabal .Caddyfile .casc .cddl .ceylon .cfc .cfm .clojure .clojurescript .yml .cmake .CMakeCache.txt .cbl .ql .coffee .cfml .confluence .ckbk .cpp .h .cr .cs .css .feature .cu .pyx .dal .dart .dhall .html .diff .d .dockerfile .dtx .env .dot .dox .drl .dust .dylan .earthfile .edge .eex .es .ex .elm .erb .erl .yaml .falcon .fql .f .ftl .fs .fthtml .gspec .gml .gcode .gen .git .glsl .glyphs .gp .go .api .gd .gr .gql .gv .groovy .haml .hbs .prg .hs .haxe .hcl .helm.tpl .hjson .hlsl .hosts .http .aff .hy .hypr .icl .imba .4gl .ini .ink .iss .io .janet .java .js .jsx .jekyll .jenkins .jinja .json .jsonc .jsonnet .json5 .jl .id .k .kv .ks .kt ..kusto .tex .lat .less .flex .ly .lisp .lhs .log .lol .lsl .lua .mk .md .marko .mat .ms .mdx .mediawiki .mel .mmd .meson.build .mjml .pq .ep .mongo .mson .ne .nim .nimble .nix .nsi .nunjucks .m .mm .ml .o3 .w .things .pas .pddl .plan .happenings .pl .pl6 .pgsql .php .pine .requirements.txt .txt .dbgasm .ddl .polymer .pony .pcss .ps1 .prisma .pde .pro .rules .properties .proto .pug .pp .purs .arr .py .pyowo .qvs .qml .qs .r .rkt .cshtml .raml .re .red .res .rst .rex .tag .rmd .robot .rb .rs .san .sas .sbt .scad .scala .sce .scss .sdl .shader .sh .slang .ice .slim .ss .sn .eskip .tpl .snort .sol .rq .sqf .sql .nut .stan .bazel .do .stencil .html.stencil .st.css .styled .styl .svelte .swagger .swift .swig .link .sv .tt .teal .tt3 .tera .tf .sty .textile .JSON-tmLanguage .YAML-tmLanguage .Tiltfile .toit .toml .ttcn3 .tuc .twig .ts .tsx .typoscript .u .vb .wsf .vm .v .vhdl .vim .volt .vue .wai .wasm .wy .wgsl .wt .wl .wurst .wxml .xmake.lua .xml .xquery .xsl .bison .yang .zig)

for filetype in "${filetypes[@]}"
do
   duti -s com.microsoft.VSCode $filetype all
   if [ $? -ne 0 ]; then
      echo "Failed to set default program for $filetype"
   fi
done
```

### How to Rename Files

Select the file and press Enter to rename it, or choose Rename from the right-click menu.

### How to Cut Files

Well, it must use Command+C and then move the file with Command+Option+V. This is Mac only, even other programs on Mac support Command+X.

Third-party enhancement tool XtraFinder does not support M1.

### How to Create a New Finder Window with a Shortcut

In Finder, use Command+N to create a window, unlike Ctrl+E, which can be very conveniently done with one hand.

### How to Copy File Names in Bulk

Well, just select multiple files with Command+C and then paste in a text editor to get the filenames, no special tools needed. ref: <https://discussions.apple.com/thread/1850895>

### How to Close All Finder Windows

In a Finder window, press Option+Command+W to close all windows of the current application.

## Applications

### Video Player

On Windows, PotPlayer is widely used for its power and simplicity. Since it's apparently not supported on Mac, I switched to an open-source tool [iina](https://iina.io/). The control bar is a bit odd, but it's manageable with keyboard controls for progress.
![1676612583239.png](https://blog.rxliuli.com/resources/f7a272132bee49a4aee730e1b75a233c.png)

### Music Player

Although iina also supports music playback, I found an open-source music player [museeks](https://museeks.io/).
![1676374490873.png](https://blog.rxliuli.com/resources/2b45e8d94c1b4dd89554f00fe02c870c.png)

### Clipboard History Management

Use the open-source program Maccy for management, GitHub: <https://github.com/p0deje/Maccy>

### How to Convert WAV+CUE to FLAC

Use [Mediahuman Audio Converter](https://www.mediahuman.com/audio-converter/welcome.html), refer to: <https://www.reddit.com/r/audiophile/comments/s7ftf3/help_with_cue_splitter_program_for_mac/>

### What to Use for Sandboxing Tools

Parallels can install Windows, but $80 is a bit expensive.

***

Solved with utm, note that downloading Windows 11 ARM is a bit troublesome. It must be downloaded and converted using a Windows system from [uup dump](https://uupdump.net/). Sharing a merged iso file, ref: <https://pan.baidu.com/s/1wDPVJRNP27dMv2s1f74TlQ#4qx8>.

Effect

![1677551846575.png](https://i.ibb.co/SVk9FbR/image.png)

### How to Record GIFs

Use the open-source tool [kap](https://getkap.co/) as a substitute for [ScreenToGif](https://www.screentogif.com/) on Windows. It doesn't support trimming and scaling the timeline but is basically usable (especially the feature of selecting application windows, it's dumb that screen recording tools don't support it).

## Development

### Disable or Modify System Shortcuts on Mac

Firstly, Ctrl+Space, which is the shortcut for switching input methods, can be modified in **Shortcuts => Input Sources**.
![1675940507249.png](https://i.ibb.co/ZTzKX5M/image.png)

Next, Ctrl+Command+Space, which by default brings up the emoji menu, can be changed in **Shortcuts => App Shortcuts** to a complex and seldom-used shortcut.
![1675940701125.png](https://i.ibb.co/M75VnHq/image.png)

Disable Command+Alt+M, the shortcut for minimizing the window, also in **Shortcuts => App Shortcuts**, change it to a complex and seldom-used shortcut.
![1676524787758.png](https://i.ibb.co/M75VnHq/image.png)

Turn off Cmd+Shift+C for creating terminals, as it easily conflicts with browser shortcuts. -- Actually, this is a VSCode shortcut.
![1676524787759.jpg](https://blog.rxliuli.com/resources/c143fa1e520845b3aa77f9cf086d8e1b.jpg)

### How to Use Shortcuts Similar to Ctrl+Home/Ctrl+End to Move the Cursor

By default, the shortcuts on Mac for moving the cursor are:

- Use Command+Up/Down to jump to the beginning/end of a line (paragraph).
- Use Option+Left/Right to jump to the beginning of the previous word/end of the next word.
- Use Command+Top/Bottom to jump to the beginning/end of the text.

All the above keys can be combined with Shift.

***

In VSCode, Command+Down is occupied by the Idea shortcut `editor.action.goToDeclaration` and needs to be disabled.

### Configuring Terminal Command Line Prompt

Use [iTerm2](https://iterm2.com/index.html) and [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh).

### Unable to Use the Run Script Feature in VSCode

Error: `The terminal process "/bin/zsh '-c', 'pnpm run dev'" failed to launch (exit code: 127).`

This is resolved after installing iTerm2 and oh-my-zsh, which is odd.

### Automatic Merging When Pulling Code with Git Pull

Currently, using `git pull` always prompts to enter a commit message, but there should be a configuration to disable this behavior.

```sh
git config --global branch.autosetupmerge always
git config --global branch.autosetuprebase always
```

ref: <https://stackoverflow.com/questions/5480069/>

> Did not take effect

### Switching Tabs in VSCode

Okay, IDEA's default Alt+Left/Right on the Windows platform conflicts with macOS's own cursor navigation. The following shortcuts can alleviate this issue:

- Command+Shift+N to open a file -- this is the JetBrains IDE shortcut.
- Command+Alt+Left/Right to move the cursor back/forward to the next position in opened files.
- Ctrl+Tab to switch tabs (obviously, this shortcut is not very convenient to press).

### Disabling Alt Key from Typing Special Characters

Unfortunately, this issue seems to be unsolvable as well; it's a behavior of the built-in macOS input method and there's no setting to change it.

### Strange Sound When Launching Android Studio

Disable the sound of the emulator:

```conf
hw.audioInput = no
hw.audioOutput = no
```

Use the following script to disable sound for all emulators:

```sh
#!/bin/bash
find ~/.android/avd -name "config.ini" | while read line
do
   awk '!/audio/' $line > tmp
   rm $line
   mv tmp $line
   echo "hw.audioInput = no" >> $line
   echo "hw.audioOutput = no" >> $line
done
```

Then clean the data and cold reboot the emulator.
![1677133915491.png](https://blog.rxliuli.com/resources/2ce3a5f07cd5403e8f036453d5286ba7.png)

### Modifying the Hosts File

```sh
sudo code /etc/hosts
```

> ref: <https://www.jianshu.com/p/752211238c1b>

### Disabling Automatic Creation of .DS_Store Files on Mac

Since using a Mac, it's easy to see this file in git submissions, and its location is unpredictable, which is annoying. So, it's desired to disable it, here is the answer from chatgpt:

You can enter the following command in the terminal to disable macOS from automatically creating .DS_Store files:

```sh
defaults write com.apple.desktopservices DSDontWriteNetworkStores true
```

This will prevent macOS from creating .DS_Store files on network volumes. If you want to prevent macOS from creating .DS_Store files in local folders, you can enter another line of command in the terminal:

```sh
defaults write com.apple.desktopservices DSDontWriteStores true
```

To make these changes take effect, you need to log out and log back into your macOS account. If you want to re-enable the creation of .DS_Store files, you can replace "true" with "false" in the above two commands and log out and back into your system account again.

### Configuring iTerm2 Terminal Shortcuts

Surprisingly, the inline cursor movement shortcuts of the widely used terminal tool on Mac are not consistent with the default Mac shortcuts. The expected consistency with Mac includes:

- Cmd+Left to move to the beginning of the line
- Cmd+Right to move to the end of the line
- Option+Left to move to the beginning of the word
- Option+Right to move to the end of the word

This requires modifying the Key Mappings Preset.

![Key Mappings Preset](https://blog.rxliuli.com/resources/1ba7f0e7000e454c8bc8c04e8ddd2257.jpg)

> ref: <https://superuser.com/a/1157575/1078727>

### Disabling iTerm2's Confirmation Prompt on Close

This option can be found in Settings => General => Closing.

![Prompt Info.jpg](https://blog.rxliuli.com/resources/3731d52caeab4167a179a8a4d127e88d.jpg)

### The Input Method Theme in JetBrains IDE Does Not Follow the System

Currently, the system theme is dark, but the input method theme is light. It seems to be a bug in JetBrains IDE, and the only workaround is to restart the IDE. Related issue: <https://youtrack.jetbrains.com/issue/IDEA-252482/>

### How to Create an ICNS Icon File

Creating and publishing a Mac app requires using a specified icon.

```sh
# 1. Prepare a single image with the maximum size of 1024x1024, rename it to icon.png; other sizes can be generated via terminal commands.
# 2. Create a folder named icons.iconset either by right-clicking or using a command.
mkdir icons.iconset
# 3. Use the "Terminal" to quickly create image files of various required sizes.
sips -z 16 16 icon.png -o icons.iconset/icon_16x16.png
sips -z 32 32 icon.png -o icons.iconset/icon_16x16@2x.png
sips -z 32 32 icon.png -o icons.iconset/icon_32x32.png
sips -z 64 64 icon.png -o icons.iconset/icon_32x32@2x.png
sips -z 128 128 icon.png -o icons.iconset/icon_128x128.png
sips -z 256 256 icon.png -o icons.iconset/icon_128x128@2x.png
sips -z 256 256 icon.png -o icons.iconset/icon_256x256.png
sips -z 512 512 icon.png -o icons.iconset/icon_256x256@2x.png
sips -z 512 512 icon.png -o icons.iconset/icon_512x512.png
sips -z 1024 1024 icon.png -o icons.iconset/icon_512x512@2x.png
# 4. Run the following command in the terminal to get the icon.icns file.
iconutil -c icns icons.iconset -o icon.icns
```

> Note: The icon.png image file and the icons.iconset folder should be saved in the same directory. Start the "Terminal" and switch to the same directory.