Last active
May 22, 2016 07:00
-
-
Save piranha/958258a705053ae788a8 to your computer and use it in GitHub Desktop.
Set desktop wallpaper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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