Created
February 13, 2019 04:19
-
-
Save ashwinreddy/113212ead19486d126252de50f22b929 to your computer and use it in GitHub Desktop.
Hammerspoon configuration to update Mac wallpaper background to the currently playing Spotify track's album artwork
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
hs.loadSpoon("ReloadConfiguration") | |
spoon.ReloadConfiguration:start() | |
function resetImage() | |
screen = hs.screen.mainScreen() | |
screen:desktopImageURL("file:///Users/areddy/Pictures/original_8ee2e1707ce7198a75211221f99e6c2d.jpeg") | |
end | |
function updateImage() | |
resetImage() | |
_, img, _ = hs.osascript.javascript("Application('Spotify').currentTrack().artworkUrl()") | |
command = "do shell script \"curl " .. img .. " > /Users/areddy/Downloads/test.jpeg\"" | |
url = "file:///Users/areddy/Downloads/test.jpeg" | |
print(img) | |
print(command) | |
print(url) | |
hs.osascript.applescript(command) | |
hs.osascript.applescript([[set this_file to "~/Downloads/test.jpeg" | |
tell application "Image Events" | |
-- start the Image Events application | |
launch | |
-- open the image file | |
set this_image to open this_file | |
-- perform action | |
pad this_image to dimensions {5120, 2880} | |
-- save the changes | |
save this_image with icon | |
-- purge the open image data | |
close this_image | |
end tell]]) | |
screen:desktopImageURL("file:///Users/areddy/Downloads/test.jpeg") | |
-- hs.osascript.applescript("tell application \"System Events\" to set picture of (reference to current desktop) to \"/Library/Desktop Pictures/Sierra 2.jpg\"") | |
-- screen = hs.screen.mainScreen() | |
-- screen:desktopImageURL(url) | |
-- _, b, _ = hs.osascript.applescript("do shell script \"/Users/areddy/anaconda3/bin/python /Users/areddy/Developer/Spotify/__main__.py\"") | |
-- print(b) | |
end | |
hs.timer.doEvery(60, function() | |
if hs.spotify.isPlaying() then | |
print("Updating image") | |
updateImage() | |
end | |
end) | |
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "B", function() | |
-- hs.spotify.displayCurrentTrack() | |
resetImage() | |
-- _, b, _ = hs.osascript.applescript("do shell script \"/Users/areddy/anaconda3/bin/python /Users/areddy/Developer/Spotify/__main__.py\"") | |
-- print(b) | |
end) | |
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "W", function() | |
-- hs.spotify.displayCurrentTrack() | |
updateImage() | |
-- _, b, _ = hs.osascript.applescript("do shell script \"/Users/areddy/anaconda3/bin/python /Users/areddy/Developer/Spotify/__main__.py\"") | |
-- print(b) | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment