Using Python with Scriptable Applications (on a Mac)

只愿长相守 提交于 2019-12-05 16:11:06

You need to use Scripting Bridge with PyObjC. There's rather a lot to it, but those links will get you started.

One possibility is to use osascript through the subprocess module. You can then have a small amount of AppleScript to access, e.g., application properties you need, but keep the logic in Python. Often, you can find online examples of the needed AppleScript reference forms, which avoids a need to dig deeply into AppleScript.

For when you start learning AppleScript ;)

tell application "iTunes"
    set selected_tracks to selection
    set track_count to count of selected_tracks
    repeat with i from 1 to track_count
        set a_track to item i of selected_tracks
        set a_track's track number to i
        set a_track's track count to track_count
    end repeat
end tell
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!