This experiment began with a specific convenience: controlling music from the terminal where I was already working. It collects shell functions for playback, pausing, changing tracks, searching the library and inspecting the current track in macOS Music.
The terminal as another interface#
The functions call AppleScript through osascript. Short commands such as music-play and music-next translate a terminal action into an application instruction. music-play-track accepts a name, searches the library and plays the first match.
The published search example passes the query as a script argument. That keeps query text separate from AppleScript source, including when it contains quotation marks or other characters that could change interpolated code.
Inspecting and debugging#
music-now-playing displays the track name, artist, album, duration and other metadata. Some fields may be unavailable, so the script handles missing values and verifies that duration is numeric before formatting it.
A second function tests track properties to identify what the installed version of Music exposes. The scope is the application and its local library; the search is not a query against the entire streaming catalog.
The ChatGPT experiment#
I used ChatGPT to prepare the functions and adjusted them when the application’s responses differed from the script’s assumptions. They became part of my dotfiles. The article preserves the process, revised code and an output example.