Flaky Goodness

Controlling TIDAL with AppleScript

May 8, 2021

I’ve been experimenting with the TIDAL streaming service but ran into a snag when I couldn’t easily play/pause audio with AppleScript. I have a nice little script (that I’ve mapped to ⌘⌥⌃ P using Alfred) that will intelligently play or pause media playback from whatever source I’m currently using. It works with Music.app, Spotify, VLC, and so on but depends on the app providing at least a basic AppleScript dictionary. No such luck with TIDAL.

Happily AppleScript can inspect and select menus in any standard macOS app menubar and we can take advantage of this for TIDAL.

2021-05-08-controlling-tidal-with-applescript.png

Figure 1: Menubar to the rescue

Menubar to the rescue

To determine whether the TIDAL app is running:

tell application "System Events"
  if exists (processes where name is "TIDAL") then
    -- TIDAL is running
  end if
end tell

To play TIDAL If it is currently paused or stopped:

tell application "System Events"
  tell process "TIDAL"
    if name of menu item 0 of menu "Playback" of menu bar 1 is "Play" then
      click menu item "Play" of menu "Playback" of menu bar 1
    end if
  end tell
end tell

To pause TIDAL if it is currently playing:

tell application "System Events"
  tell process "TIDAL"
    if name of menu item 0 of menu "Playback" of menu bar 1 is "Pause" then
      click menu item "Pause" of menu "Playback" of menu bar 1 
    end if
  end tell
end tell

To toggle the play/pause state:

tell application "System Events"
  tell process "TIDAL"
    click menu item 0 of menu "Playback" of menu bar 1
  end tell
end tell

Just as with any UI scripting approach, this method is fragile and won’t survive, for example, a TIDAL UI revamp. But it’s better than nothing and simple enough to tweak in the future if necessary.