开发者

How do I get the file path of an iTunes Selection

I'm trying to determine the path of track select开发者_运维技巧ed 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?


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


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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜