Skip to content

Instantly share code, notes, and snippets.

@obvyah
Last active March 27, 2019 06:01
Show Gist options
  • Save obvyah/3788df039fb43fc8e089 to your computer and use it in GitHub Desktop.
Save obvyah/3788df039fb43fc8e089 to your computer and use it in GitHub Desktop.
if you haven't decided to pay for spotify Premium, you can execute this applescript on your mac to Mute Spotify Advertisements and unmute Spotify when playing your fav musics automatically.
global check_every, adDuration
set check_every to 20
set adDuration to 31000
display dialog "Start to Check AD of Spotify every " & check_every & " seconds."
on reopen
display dialog "Start to Check AD of Spotify every " & check_every & " seconds."
end reopen
repeat while (application "Spotify" is running)
tell application "System Events"
set num to count (every process whose name is "Spotify")
end tell
if num > 0 then
tell application "Spotify"
set playState to (player state as text)
if playState is equal to "playing" then
set trackName to name of current track
set artistName to artist of current track
set albumName to album of current track
set trackDuration to duration of current track
set trackInfo to trackName & " | " & artistName & " | " & albumName & " | " & trackDuration
if trackName is equal to "Spotify" or trackDuration is less than adDuration then
set volume with output muted
else
set volume without output muted
end if
else
set trackInfo to "Nothing playing"
end if
do shell script "echo " & quoted form of trackInfo & " > $HOME/Desktop/Test.txt"
end tell
else
set trackInfo to "Nothing playing"
do shell script "echo " & quoted form of trackInfo & " > $HOME/Desktop/Test.txt"
end if
delay check_every
end repeat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment