Python to replace AppleScript targeting Apple Music
Posted: Fri Jan 06, 2023 9:40 am
Since the iTunes plugin doesn't work any more, and iTunes Local Control doesn't return track info, and AirFoil Pro is flaky as hell on my network while AirPlay works just fine, I'm trying to figure out how to get track info into Indigo, including being able to trigger on play pause.
Anyone achieving this currently?
My fumbling and ChatAI-assisted attempt has gotten close, but still generates errors I can't work around:
That AppleScript is supposed to target this Python:
My current thought about moving forward is super kludgy and would involve a repeating Indigo Schedule running every 15 seconds or so, running a python script that looks for changes in a file created by AppleScript with the Apple Music info I want, and that then updates variables if the file has changed.
Hopefully there's a better way. This seems like a thing someone out there who actually understands Python would already have working.
Anyone achieving this currently?
My fumbling and ChatAI-assisted attempt has gotten close, but still generates errors I can't work around:
- Code: Select all
tell application "Music"
set currentTrack to current track
set trackName to name of currentTrack
set artistName to artist of currentTrack
set trackInfo to trackName & "|" & artistName
end tell
set pythonScript to "insert_track_info.py"
set pythonPath to "/Library/Frameworks/Python.framework/Versions/3.10/bin/python3"
set scriptPath to quoted form of "/Library/Application Support/Perceptive Automation/Scripts/" & pythonScript
set trackInfo to trackName & "|" & artistName
#do shell script quoted form of pythonPath & " " & quoted form of scriptPath & " " & quoted form of trackInfo
do shell script quoted form of "/Library/Application Support/Perceptive Automation/Scripts/insert_track_info.py"
That AppleScript is supposed to target this Python:
- Code: Select all
import indigo
import sys
trackInfo = sys.argv[1]
trackName, artistName = trackInfo.split("|")
indigo.variable.updateValue(trackVariableId, value=trackName)
indigo.variable.updateValue(artistVariableId, value=artistName)
My current thought about moving forward is super kludgy and would involve a repeating Indigo Schedule running every 15 seconds or so, running a python script that looks for changes in a file created by AppleScript with the Apple Music info I want, and that then updates variables if the file has changed.
Hopefully there's a better way. This seems like a thing someone out there who actually understands Python would already have working.