Skip to content

Instantly share code, notes, and snippets.

@mph-code
Forked from alisonailea/AwakenSpotify.scpt
Created September 21, 2019 19:56
Show Gist options
  • Save mph-code/76fe42f5b97445d2f5f7e24d6cf9d05c to your computer and use it in GitHub Desktop.
Save mph-code/76fe42f5b97445d2f5f7e24d6cf9d05c to your computer and use it in GitHub Desktop.
AppleScript to automate the Spotify playlist launch based on the time of day
--current time in seconds since midnight
set currentTime to (time of (current date))
## Morning
-- (04:00 - 10:30)
set morning to 37800
set morningVolume to 80
-- Happy: Wake Up in a Good Mood
set morningTrack to "spotify:user:116779154:playlist:5sYrf2RnhPY22meUSS5fUu"
## Afternoon
-- (10:30 - 16:30)
set afternoon to 54800
set afternoonVolume to 80
-- Totally Stress Free
set afternoonTrack to "spotify:user:spotify:playlist:7jq9hVhkNUyFLN1XivhLvK"
## Evening
-- (16:30 - 22:00)
set evening to 79200
set eveningVolume to 60
-- Evening Chill
set eveningTrack to "spotify:user:spotify:playlist:0eDq2STmk8tKcD7qWCwrze"
## Night
-- (22:00 - 04:00)
set night to 14400
set nightVolume to 50
-- Sleep Tight
set nightTrack to "spotify:user:spotify:playlist:1YRQAGw7qVJCLxWFGDsS3l"
set scriptVolume to null
set scriptTrack to null
if currentTime is less than night and currentTime is greater than 0 then
set scriptVolume to nightVolume
set scriptTrack to nightTrack
else if currentTime is less than morning and currentTime is greater than night then
set scriptVolume to morningVolume
set scriptTrack to morningTrack
else if currentTime is less than afternoon and currentTime is greater than morning then
set scriptVolume to afternoonVolume
set scriptTrack to afternoonTrack
else if currentTime is less than evening and currentTime is greater than afternoon then
set scriptVolume to eveningVolume
set scriptTrack to eveningTrack
else
set scriptVolume to nightVolume
set scriptTrack to nightTrack
end if
tell application "Spotify"
launch
delay 3
set sound volume to (scriptVolume)
play track scriptTrack
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment