Cheat Sheet

MacOS tips and tricks.

General

Allow Apps from Anywhere in Gatekeeper for macOS Catalina, macOS Mojave, MacOS Sierra

sudo spctl --master-disable

Sign app

codesign --force --deep --sign - /Applications/AppName.app

Arrange windows

Split view

https://support.apple.com/en-us/HT204948

Spectacle

https://www.spectacleapp.com/

https://www.howtogeek.com/288124/how-to-rearrange-your-macs-windows-with-a-keyboard-shorcut/

Automator

Shortcut to open iTerm2

Press Command + space bar to launch Spotlight. Run automator.

Create a New Document type Quick Action.

Setup the new Action as follows.

Save the as as Open iTerm2.

Open and change the keyboard shortcut config as follows (you can change the shortcut key combination).

Custom printscreen

Automate printscreen with no screen border or shadow.

Create the following script anywhere in you computer.

#!/usr/bin/osascript

tell application "iTerm" to activate

tell application "System Events"
    keystroke "$" using {command down, shift down}
    delay 1
    key code 49 -- space bar
    delay 1
    key down {option}
    display notification "Printscreen is ready" with title "Custom printscreen READY" subtitle "Capture window" sound name "Frog"
    delay 5
    key up {option}
    display notification "Printscreen finished" with title "Custom printscreen FINISHED" subtitle "Capture window" sound name "Frog"
    delay 1
    key up {option}
end tell

Save it and make sure to chmod +rx it.

Press Command + space bar to launch Spotlight. Run automator.

Create a New Document type Quick Action.

Setup the new Action as follows.

Save it as "Custom snap".

Make sure to "Run" it before creating a keyboard shortcut because it requires some MacOS "allow" actions.

To create a keyboard shortcut go to Settings -> Keyboard as follows.

Copy to clipboard the URL of all Safari tabs

#!/usr/bin/osascript

tell application "Safari"
    set docText to ""
    set windowCount to count (every window where visible is true)
    repeat with x from 1 to windowCount
        set tabCount to number of tabs in window x
        repeat with y from 1 to tabCount
            set tabName to name of tab y of window x
            set tabURL to URL of tab y of window x as string
            set docText to docText & tabName & " – " & tabURL & linefeed as string
        end repeat
        set the clipboard to the docText
    end repeat
end tell

Defaults

Screenshots path

defaults write com.apple.screencapture location /new/path/for/screenshots

Docker

Bash auto complete

Install bash-completion:

brew install bash-completion

Install docker-compse auto complete:

sudo curl -L https://raw.githubusercontent.com/docker/compose/1.24.0/contrib/completion/bash/docker-compose -o /usr/local/etc/bash_completion.d/docker-compose
sudo chmod +x /usr/local/etc/bash_completion.d/docker-compose

Create symbolic links:

cd /usr/local/etc/bash_completion.d
ln -s /Applications/Docker.app/Contents/Resources/etc/docker.bash-completion
ln -s /Applications/Docker.app/Contents/Resources/etc/docker-machine.bash-completion
ln -s /Applications/Docker.app/Contents/Resources/etc/docker-compose.bash-completion

Edit bash_profile:

vi ~/.bash_profile

Add the following content:

[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"

if [ -f $(brew --prefix)/etc/bash_completion ]; then
 . $(brew --prefix)/etc/bash_completion
fi

Open a new terminal and test.

Monitoring

public-apis

osascript

Activate window

Activate the app, to bring it to the front

osascript -e "tell application \"iTerm\" to activate" 

User other app names such as Chrome.

Resize window in pixels

Bounds is startX, startY, endX, endY.

osascript -e "tell application \"iTerm\" to set the bounds of the first window to {0, 0, 1920, 1080}"

User other app names such as Chrome.

Last updated