Skip to content

Instantly share code, notes, and snippets.

@alisonailea
Last active December 8, 2023 22:05
Show Gist options
  • Save alisonailea/7d14fdabf2658ef2ccf2 to your computer and use it in GitHub Desktop.
Save alisonailea/7d14fdabf2658ef2ccf2 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
@tberry305
Copy link

I need an Apple script to play only 63sec of each song in my play list.

@brodman1993
Copy link

brodman1993 commented Dec 4, 2017

Is there a way to get a playlist to play on curtain days at curtain times?

Say I wanted a playlist to play on Sunday morning from 08:00 to 09:05.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment