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

![](/files/-LqQqvTFV0VaSkmmJ-UJ)

Save the as as **Open iTerm2**.

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

![](/files/-LqQrWkkukG320vVKXuX)

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

![](/files/-M-WHNQgp2jdP0mMlABX)

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.

![](/files/-M-WHjz9lrrJYzr74Oj9)

### 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 %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.devops.buzz/public/macos/cheat-sheet.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
