How do I get the file path of an iTunes Selection

时光毁灭记忆、已成空白 提交于 2019-12-23 22:23:42

问题


I'm trying to determine the path of track selected in iTunes using AppleScript. It doesn't seem to be a property of the track class. Can anyone tell me how I can get the file path?


回答1:


Try this:

--gets file path of selected song
tell application "iTunes"
 set songLocation to get location of selection
end tell
return songLocation

--gets file path of currently playing song
tell application "iTunes"
 set songLocation to get location of current track
end tell
return songLocation



回答2:


If you're going to use Python instead of AppleScript and don't want to parse the plist XML file, you can get the file path through the COM API.

import win32com.client

iTunes = win32com.client.gencache.EnsureDispatch("iTunes.Application")
currentTrack = win32com.client.CastTo(iTunes.CurrentTrack,"IITFileOrCDTrack")

print currentTrack.Location



回答3:


If it's not available through AppleScript, your best bet will be to open and parse the iTunes plist file. If you only need static information, you're golden. If you need dynamic information (for example, info on the track that's currently playing), you'll want to get the track's persistent ID through AppleScript, then parse the plist file and lookup any info you need (including location, which has the full path).

For parsing that plist XML file (in ~/Music/iTunes/iTunes Music Library.xml), you can use ruby or python or any other language you like. If you like python, try this library:

http://docs.python.org/library/plistlib.html



来源:https://stackoverflow.com/questions/1864870/how-do-i-get-the-file-path-of-an-itunes-selection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!