Last active
September 15, 2025 22:50
-
-
Save mortenson/04a16feddf07473ee021c819c3ea7f0c to your computer and use it in GitHub Desktop.
AppleScript to slowly lower Spotify volume when you're not working, to incentivize being more productive! π§
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
# spotify_focuser.applescript | |
# An AppleScript script that decreases Spotify volume while you're not using work related apps and websites. | |
# by Samuel Mortenson | |
# To install, download this script and open it in Script Editor, then select File > Export and export the script as an Application with "Stay open after run handler" checked. Now you can run the exported Application and GET BACK TO WORK! | |
# You shouldn't normally run random AppleScript or give it permissions, so uh read the code first before doing something dumb. | |
# Other notes: | |
# - Volume is only changed when a song is playing | |
# - Volume does not change while Spotify is open, to stay neutral about whether or not that is work related | |
# - Only Chrome and Safari are supported for checking for work related domains, Firefox AppleScript is awkward | |
# - Spotify volume is set to 100% on launch and moves towards that while working, it's assumed you'll have this open as a part of Login Items so the volume of Spotify when the script opens is ignored | |
# You can edit the following lists to fit your needs. | |
# To find the bundle ID (com.*) of an Application, you can run `osascript -e 'id of app "Safari"`. | |
property workRelatedApps : {"com.microsoft.VSCode", "com.todesktop.230313mzl4w4u92", "com.googlecode.iterm2", "com.1password.1password", "com.apple.Terminal", "com.apple.finder", "com.apple.TextEdit", "com.apple.systempreferences"} | |
property workRelatedDomains : {"github.com", "notion.so", "google.com", "stackoverflow.com", "mercury.com", "localhost", "127.0.0.1", "0.0.0.0", ".local"} | |
property currentVolume : 100 | |
property volumeUpTick : 20 | |
property volumeDownTick : 5 | |
property safariBrowserUrl : "" | |
property chromeBrowserUrl : "" | |
on run | |
checkWindowStatus() | |
end run | |
on idle | |
checkWindowStatus() | |
return 1 | |
end idle | |
on checkWindowStatus() | |
# Get the bundle ID (com.*) of the focused app | |
tell application "System Events" | |
set frontAppProcess to bundle identifier of first application process whose frontmost is true | |
end tell | |
# If chrome is open, get the open tab url | |
tell application "Google Chrome" | |
if it is running then | |
set chromeBrowserUrl to get URL of active tab of first window as text | |
end if | |
end tell | |
# If safari is open, get the open tab url | |
tell application "Safari" | |
if it is running then | |
set safariBrowserUrl to get URL of the current tab of the front window as text | |
end if | |
end tell | |
set chromeUrlWorkRelated to false | |
set safariUrlWorkRelated to false | |
repeat with domain in workRelatedDomains | |
if chromeBrowserUrl contains domain then | |
set chromeUrlWorkRelated to true | |
end if | |
if safariBrowserUrl contains domain then | |
set safariUrlWorkRelated to true | |
end if | |
end repeat | |
tell application "Spotify" | |
if it is running and player state is playing then | |
if frontAppProcess is "com.google.Chrome" and chromeUrlWorkRelated then | |
set currentVolume to currentVolume + volumeUpTick | |
else if frontAppProcess is "com.apple.Safari" and safariUrlWorkRelated then | |
set currentVolume to currentVolume + volumeUpTick | |
else if workRelatedApps contains frontAppProcess then | |
set currentVolume to currentVolume + volumeUpTick | |
else if frontAppProcess is not "com.spotify.client" then | |
set currentVolume to currentVolume - volumeDownTick | |
end if | |
if currentVolume > 100 then | |
set currentVolume to 100 | |
else if currentVolume < 0 then | |
set currentVolume to 0 | |
end if | |
if sound volume is not currentVolume then | |
if currentVolume is 0 then | |
display notification "you slacked off so long your music got muted bruh πππππ" | |
else if sound volume is 0 then | |
display notification "π£οΈπ£οΈπ£οΈ GOOD JOB PUMP UP THE VOLUME" | |
end if | |
set sound volume to currentVolume | |
end if | |
end if | |
end tell | |
end checkWindowStatus |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment