3

我正在尝试使用 AppleScript 确定在 iTunes 中选择的曲目路径。它似乎不是track该类的属性。谁能告诉我如何获取文件路径?

4

3 回答 3

7

尝试这个:

--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
于 2009-12-08T06:13:42.167 回答
1

如果您打算使用 Python 而不是 AppleScript 并且不想解析 plist XML 文件,您可以通过 COM API 获取文件路径。

import win32com.client

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

print currentTrack.Location
于 2010-11-05T19:48:05.350 回答
0

如果它不能通过 AppleScript 获得,最好的办法是打开并解析 iTunes plist 文件。如果您只需要静态信息,那么您就是黄金。如果您需要动态信息(例如,当前正在播放的曲目的信息),您需要通过 AppleScript 获取曲目的持久 ID,然后解析 plist 文件并查找您需要的任何信息(包括location,它具有完整的小路)。

要解析该 plist XML 文件(在 ~/Music/iTunes/iTunes Music Library.xml 中),您可以使用 ruby​​ 或 python 或您喜欢的任何其他语言。如果你喜欢 python,试试这个库:

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

于 2009-12-08T06:14:19.590 回答