Temporarily Pause iTunes

There was a webcomic that went viral years ago where the hero pauses his iPod (i said years ago!), takes care of something, then forgets to resume the music until hours later. I did this all the time. so I wrote a macro that will pause iTunes for 5 minutes, then automatically restart playing.

It sounded simple at first but over the years of using it i found a lot of edge cases that ended up making the macro somewhat complex. I thought others might be interested in seeing it.

The basic case of when the hotkey is hit pause iTunes is pretty simple. As is waiting 5 minutes, then starting iTunes again. But the issues I ran into were:

  1. What if I remember to resume the music (rare but happens), how can i restart easily?
  2. If I restart, what happens when the previous pause that is waiting 5 minutes expires?
  3. what if i paused iTunes via the regular pause button in itunes?

My answers were:

  1. hit the same hotkey (I use F15, which on my keyboard is labeled Pause) again and play should resume.
  2. the previous still running macro should be terminated.
  3. The hotkey should start playing if itunes is currently running, no matter how it was paused.

This added some tricky state tracking to the macro. I had to know if I had already started a macro that had paused itunes and was waiting. You can't check if a specific macro is running (hint @peternlewis) or kill a specific instance of a running macro (cough).

My solution was variables. I use one variable to identify that the macro is currently running. I use another variable to check the current state of the iTunes player (set via applescript checking iTunes).

The one tricky If statement in the Macro is the second one. Note it is an If NO Condition Met test. That means if the variable iTunesPlayState contains "play" then skip the pause/resume.

Also the last command is "Set Variable 'iTunesControl' to Text and the to is blank. I'm clearing the variable out when the macro ends.

Temp Pause iTunes.kmmacros (6.0 KB)


I have a sister macro to this that is really easy to write called Permanent Pause iTunes. Shift+Pause (shift+F15 in KM) permanently pauses iTunes for me. It also detects if the temporary pause macro is running and kills it if it is. then clears the iTunesControl variable as well.