Skip to content

Instantly share code, notes, and snippets.

@robotsandcake
Last active April 4, 2017 10:05
Show Gist options
  • Select an option

  • Save robotsandcake/3afc1d24f6b65e8bceb8e274ca460195 to your computer and use it in GitHub Desktop.

Select an option

Save robotsandcake/3afc1d24f6b65e8bceb8e274ca460195 to your computer and use it in GitHub Desktop.
This AppleScript will toggle the iTunes player on macOS between two states, play and pause. It can be triggered from any application that can trigger AppleScripts.
try
-- Specify the application will want to work on, in this case iTunes.
tell application "iTunes"
-- Get iTunes current state
if player state is paused then
-- If iTunes is paused, press play.
play
-- Get iTunes state if it doesn't match the first condition
else if player state is playing then
-- If iTunes is playing, press pause.
pause
end if
end tell
end try
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment