Here are a couple of macros that leverage AppleScript to accomplish some basic Music tasks without having to interface with the Music app UI directly.
The "Display" macro is self-explanatory. The "Add" macro gets a list of your playlists and prompts you to choose one from the list. Then it adds the currently playing track to the chosen playlist.
Each macro displays a AppleScript generated notification dialog which persists until you hit spacebar or enter, or until a few seconds have elapsed, whichever comes first. You can adjust how many seconds by changing the number after "giving up after" in the AppleScript. You can replace that with the KM notification if you like. I like customizing my notifications with AS.
Important: The "Add Current Track to Playlist" macro should be invoked only while music from your Music Library, and not from Apple Music, is playing. If you trigger it while playing a track in Apple Music, you'll get an error. The track needs to be in your Music Library in order for this macro to be able to add it to one of your playlists.
The "Display Current Track" macro will work with any track, including a track in Apple Music.
(These macros are uploaded in a disabled state. You'll need to enable them after you install them in KM.)
DISPLAY CURRENT TRACK.kmmacros (2.5 KB)
ADD CURRENT TRACK TO PLAYLIST.kmmacros (4.7 KB)
And for good measure, here is an Applescript for adding the currently playing Apple Music track to your library:
You do realize there are text-tokens for:
Keyboard Maestro Editor › Edit › Insert Token › iTunes
This was just brought to my attention -- by you! Thanks, man! My bad!
Thanks for this! The last AppleScript for adding Apple Music tracks to your library is particularly helpful. With no scripting experience, I've been using KM to automate some menu based actions in Music (like simultaneously giving 5 star ratings and loving a particularly good song) but for some reason the song based menu items only work when listening to songs already in your library. The menu appears to be grey when streaming Apple Music songs (i.e. not in your library yet). It goes without saying that the script is helpful when coming across new music while listing to your station or any of the curated mixes on Apple Music.
Would it be greedy to ask what this script would look like if you also wanted to add the full album on which the song (added by the original script) appears to your library?
I am not sure, but try replacing the variable "current_track" to "current_album" and inserting "the album of" before "the current track" in the script. I have no idea if it will work...
Works for me. The track has to be in your library - not just in Apple Music. If you're listening to a song in Apple Music, you need to add it to your library, then play the song from your library, and then run the macro. It's too bad you can't just use the macro while you're sampling tracks on Apple Music, but the system just won't allow it.