I am trying to write an AppleScript that will tell me the current playing song, but I am unable to read properties from objects in AppleScript.
Executing a function on music works fine such as
tell application "Music" to play
tell application "Music" to pause
But trying to read a property such as the current track title does not. In fact, even trying to read the properties of the current track does not work. (Tested while a song was playing)
tell application "Music" to get properties of current track
returns error "Music got an error: Can’t get properties of current track." number -1728 from properties of current track
Per this question, the above script should work: AppleScript and Music
I did get this to work when I was trying before when I was looking at the permissions, but then it stopped working since then so it might have been working for another reason. I'm running the script in script editor, which does have accessibility access in my security & privacy settings.
Possibly related issue: Applescript - Getting Property of an Object Not Working
tell application "Music" to get properties of current track
in Script Editor returns the properties of the currently playing track in Music. Note that the currently playing track is a file located on the local disk. Where is the file located of the currently playing track that you get the error for?do shell script "osascript -e 'tell application \"Music\" to activate'"
to the top of your script, then run your saved version, not from Script Editor itself. It seems to work to ask for perms. (You can trash the line once it works)current track
vs. on on the local disk under macOS Big Sur.