# Cheat Sheet

## General

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

```bash
sudo spctl --master-disable
```

### Sign app

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

## Arrange windows

### Split view

Hold down the full-screen button ![ ](https://support.apple.com/library/content/dam/edam/applecare/images/en_US/osx/el-cap-split-screen-icon.png) in the upper-left corner of a window.&#x20;

<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.

![](https://1923299483-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LVfLS9KLUfusOjV0FX_%2F-LqQpWcAIMQ4JQksBF15%2F-LqQqvTFV0VaSkmmJ-UJ%2Fimage.png?alt=media\&token=2a5cb008-288d-499d-a374-6d2493750208)

Save the as as **Open iTerm2**.

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

![](https://1923299483-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LVfLS9KLUfusOjV0FX_%2F-LqQpWcAIMQ4JQksBF15%2F-LqQrWkkukG320vVKXuX%2Fimage.png?alt=media\&token=a4cd6d74-bfcc-4f18-adb8-42c3b86b780a)

### Custom printscreen

Automate printscreen with no screen border or shadow.

Create the following script anywhere in you computer.

```bash
#!/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.

![](https://1923299483-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LVfLS9KLUfusOjV0FX_%2F-M-WHE0gYHYzOsQFh6sm%2F-M-WHNQgp2jdP0mMlABX%2Fimage.png?alt=media\&token=770fe559-84ff-49df-9be1-5ae000cec353)

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.

![](https://1923299483-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LVfLS9KLUfusOjV0FX_%2F-M-WHE0gYHYzOsQFh6sm%2F-M-WHjz9lrrJYzr74Oj9%2Fimage.png?alt=media\&token=93edab61-14c7-4e5c-a9b4-5f7d51b2b12e)

### Copy to clipboard the URL of all Safari tabs

```bash
#!/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

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

## Docker

### Bash auto complete

Install bash-completion:

```bash
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:

```bash
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:

```bash
[[ -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

{% embed url="<https://github.com/public-apis/public-apis>" %}

## osascript

### Activate window

Activate the app, to bring it to the front

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

{% hint style="info" %}
User other app names such as Chrome.
{% endhint %}

### Resize window in pixels

Bounds is startX, startY, endX, endY.

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

{% hint style="info" %}
User other app names such as Chrome.
{% endhint %}
