Skip to content

Instantly share code, notes, and snippets.

@andrewp-as-is
Last active February 27, 2024 20:13
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save andrewp-as-is/9f9134f6ae38bf515265865df904a9a9 to your computer and use it in GitHub Desktop.
Save andrewp-as-is/9f9134f6ae38bf515265865df904a9a9 to your computer and use it in GitHub Desktop.
macOS Dock scripts
#!/usr/bin/env bash
path=/Applications/Automator.app
defaults write com.apple.dock persistent-apps -array-add "<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>$path</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>"; killall Dock
#!/usr/bin/env bash
defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="spacer-tile";}'; killall Dock
defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="small-spacer-tile";}'; killall Dock
defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="flex-spacer-tile";}'; killall Dock
#!/usr/bin/env bash
path=~/Downloads
label="${path##*}"
arrangement=1 # 1 - name (default), 2 - added, 3 - modification, 4 - creation, 5 - kind
displayas=2 # 1 - folder, 2 - stack (default)
showas=4 # 1 - beep, 2 - grid, 3 - list, 4 - auto (default)
tmp="$(mktemp)" || exit
cat <<EOF > "$tmp"
<dict>
<key>tile-data</key>
<dict>
<key>file-data</key>
<dict>
<key>_CFURLString</key>
<string>$path</string>
<key>_CFURLStringType</key>
<integer>0</integer>
</dict>
<key>file-label</key>
<string>$label</string>
<key>arrangement</key>
<integer>$arrangement</integer>
<key>displayas</key>
<integer>$displayas</integer>
<key>showas</key>
<integer>$showas</integer>
</dict>
<key>tile-type</key>
<string>directory-tile</string>
</dict>
EOF
value="$(cat "$tmp")" || exit
defaults write com.apple.dock persistent-others -array-add "$value"; killall Dock
#!/usr/bin/env bash
defaults read com.apple.dock persistent-apps | grep '"_CFURLString"' | awk -F'"' '{print $4}' | php -R 'echo urldecode($argn)."\n";' | sed -e 's/file:\/\///g' | sed -e 's/\/$//g'
#!/usr/bin/env bash
defaults read com.apple.dock persistent-others | grep '"_CFURLString"' | awk -F'"' '{print $4}' | php -R 'echo urldecode($argn)."\n";' | sed -e 's/file:\/\///g' | sed -e 's/\/$//g'
#!/usr/bin/env bash
path=/Applications/Automator.app
dloc="$(defaults read com.apple.dock persistent-apps | grep '"_CFURLString"' | grep -n "$path" | cut -f1 -d:)"
[[ -n "$dloc" ]] && {
dloc=$[$dloc-1]
/usr/libexec/PlistBuddy -c "Delete persistent-apps:$dloc" ~/Library/Preferences/com.apple.dock.plist
killall Dock
};:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment