Skip to content

Instantly share code, notes, and snippets.

@piranha
Last active May 22, 2016 07:00
Show Gist options
  • Save piranha/958258a705053ae788a8 to your computer and use it in GitHub Desktop.
Save piranha/958258a705053ae788a8 to your computer and use it in GitHub Desktop.
Set desktop wallpaper
#!/bin/sh
if [ -z "$1" ]; then
echo "Usage: $0 <path-to-wallpaper>"
exit 1
fi
realpath() {
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}
IMG=$(realpath $1)
echo "Changing wallpaper to $IMG"
DB=~/Library/Application\ Support/Dock/desktoppicture.db
IMGID=$(sqlite3 "$DB" "select rowid from data where value = '$IMG'")
if [ -z "$IMGID" ]; then
sqlite3 "$DB" "insert into data (value) values ('$IMG')"
IMGID=$(sqlite3 "$DB" "select rowid from data where value = '$IMG'")
fi
sqlite3 "$DB" "delete from preferences where key = 1"
sqlite3 "$DB" "insert into preferences (key, data_id, picture_id) select 1, $IMGID, rowid from pictures"
killall Dock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment