Skip to content

Instantly share code, notes, and snippets.

@st44100
Last active July 25, 2018 02:51
Show Gist options
  • Save st44100/158fa67653373648fdda0451a93337a7 to your computer and use it in GitHub Desktop.
Save st44100/158fa67653373648fdda0451a93337a7 to your computer and use it in GitHub Desktop.
Change wallpeper from CLI
#!/bin/sh
# resolve $PATH
export PATH=$HOME/.nvm/versions/node/v8.9.2/bin/:$PATH
export PATH=$HOME/bin/:$PATH
export PATH=/usr/local/bin/:$PATH
# Fetch current song picture from spotify.
spotify share | sed -e '2d' -e 's/^SpotifyURI://' | xargs -ISONG_URL curl -X GET https://open.spotify.com/oembed\?url\=SONG_URL | jq '.thumbnail_url' | xargs -IIMAGE_URL wget IMAGE_URL -O ~/Pictures/spotify-wallpaper.jpg
# デスクトップピクチャは同一ファイル名への変更ができないので、一度別のものに変える
osascript<<END
tell application "System Events"
tell current desktop
set picture to "~/Pictures/placeholder.png"
end tell
end tell
END
# Sleepなしで実行すると、どちらかのピクチャ変更処理がキャンセルされる
sleep 1
osascript<<END
tell application "System Events"
tell current desktop
set picture to "~/Pictures/spotify-wallpaper.jpg"
end tell
end tell
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment