Skip to content

Instantly share code, notes, and snippets.

@comigor
Created March 18, 2019 13:47
Show Gist options
  • Save comigor/8c8da45af239c90d34f8df6f056291e0 to your computer and use it in GitHub Desktop.
Save comigor/8c8da45af239c90d34f8df6f056291e0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
if [[ "$OSTYPE" != "darwin"* ]]; then
echo "macOS only. Sorry."
exit 1
fi
function changeWallpaper() {
osascript -e 'tell app "finder" to get posix path of (get desktop picture as alias)' > /tmp/old_wallpaper_path
curl -s 'https://conteudo.imguol.com.br/2012/09/25/vampeta-fala-sobre-ensaio-nu-para-a-g-magazine-1348607286095_956x500.jpg' > /tmp/vampeta.jpg
osascript -e 'tell application "System Events" to tell every desktop to set picture to "/tmp/vampeta.jpg"'
}
function revertWallpaper() {
readonly local old_wallpaper_path=$(cat /tmp/old_wallpaper_path)
osascript -e 'tell application "System Events" to tell every desktop to set picture to "'$old_wallpaper_path'"'
}
function paintItBlack() {
osascript <<END
tell application "System Preferences"
reveal anchor 13 of pane id "com.apple.preference.universalaccess"
end tell
tell application "System Events"
tell checkbox "Use grayscale" of group 1 of window "Accessibility" of application process "System Preferences"
if value is 0 then click it
end tell
set value of slider "Cursor size:" of group 1 of window "Accessibility" of application process "System Preferences" to 4.0
set value of slider "Display contrast:" of group 1 of window "Accessibility" of application process "System Preferences" to 1.0
end tell
END
}
function colorize() {
osascript <<END
tell application "System Preferences"
reveal anchor 13 of pane id "com.apple.preference.universalaccess"
end tell
tell application "System Events"
tell checkbox "Use grayscale" of group 1 of window "Accessibility" of application process "System Preferences"
if value is 1 then click it
end tell
set value of slider "Cursor size:" of group 1 of window "Accessibility" of application process "System Preferences" to 0.0
set value of slider "Display contrast:" of group 1 of window "Accessibility" of application process "System Preferences" to 0.0
end tell
END
}
if [ "${revert}" != "false" ]; then
revertWallpaper
colorize
else
changeWallpaper
paintItBlack
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment