如何获取 iTunes 选择的文件路径

发布于 2024-08-14 02:56:53 字数 92 浏览 6 评论 0原文

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

故乡的云 2024-08-21 02:56:53

试试这个:

--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

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
千年*琉璃梦 2024-08-21 02:56:53

如果无法通过 AppleScript 获得它,则最好的选择是打开并解析 iTunes plist 文件。如果您只需要静态信息,那就太好了。如果您需要动态信息(例如,当前正在播放的曲目的信息),您需要通过 AppleScript 获取曲目的持久 ID,然后解析 plist 文件并查找您需要的任何信息(包括位置,其中包含完整路径)。

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

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

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

客…行舟 2024-08-21 02:56:53

如果您打算使用 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文