Chat GPT Generated AppleScript for Music

By Kevin Shaw, 8 January, 2023

Forum
macOS and Mac Apps

Have you ever been listening to the Music app on Mac OS and went, "Oh, I wonder what song this is?"
For me, that means command-tabbing to the Music app, getting to the LCD area, interacting and then reading the song title and artist.
Wouldn't it be great to hit one key and hear song title and artist, no matter what app you were in?
Well, thanks to Chat GPT, we now have a simple AppleScript that does this.

Copy the below text into ScriptEditor which is in your Utilities folder.
Make a new script and paste the below text.

tell application "Music"
set currentTrack to current track
set trackName to name of currentTrack
set artistName to artist of currentTrack
set trackInfo to "Now playing: " & trackName & " by " & artistName
tell application "VoiceOver"
say trackInfo
end tell
end tell

Command S to save. Give it a name and save it. I used the default folder.
Open VoiceOver Utility and navigate to Commanders>Keyboard.
Add a keystroke and select Custom Commands from the menu. Choose run AppleScript. Navigate to the file you saved. For me, I used the default ScriptEditor folder on iCloud Drive and right-option Q for the keystroke.

Now, when I hit right-option Q, VoiceOver says the song title and artist of the currently playing song. Pretty nifty.

Pretty nifty, eh?

Options

Comments

By peter on Thursday, January 26, 2023 - 18:45

Yes, chat GPT can be used to write code in almost any language. Sometimes it isn't perfect, but can be a very good template or starting point. If it does produce code that makes an error when run, you can also tell the AI what error was produced and it will atempt to fix the code. thus you can use this interactively to improve and/or enhance code it writes.

I've also used it to write lyrics for songs. Pretty cool.

--Pete