3

The audio section of the touch bar can automatically detect which app is playing audio, and adds media controls to play/pause, skip, and seek through any audio. As an example, this works for Quicktime, Spotify, and even YouTube audio from browsers like Google Chrome. How can I use AppleScript to mimic these functions? I want to get the name of the song, be able to play/pause, skip, and even seeking if that is possible.

2 Answers 2

1

I made a cli tool that lets you read properties from the private MediaRemote framework.

https://github.com/kirtan-shah/nowplaying-cli

Since it uses private APIs, it may break with future macOS updates but is currently working on Ventura 13.1.

Here is an example that will retrieve the song name: now playing center screenshot

nowplaying-cli usage

The tool also supports commands like play/pause:

nowplaying-cli play

If you want to call this from AppleScript you can use the following syntax:

do shell script "<your command>"
1
  • This is amazing -- thank you for your work on this! All other solutions to detect audio playing on OSX are dirty hacks.
    – nyxaria
    Apr 27 at 19:50
-1

This is a very useful tool and I have a recommendation on the best place to learn how to use AppleScript to interact with media.

This is 100% possible and you might even find the exact script you need, already written. Worst case, you can see the code and hopefully adapt one to your needs.

1
  • 1
    OP mentioned the general interface that was introduced in maybe 10.12+, not itunes specific. For that you can use MPNowPlayingInfoCenter link. If you want to do from pure applescript, maybe use obj-c bridge?
    – 1110101001
    Dec 25, 2021 at 21:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .