How to get the path to the iTunes Selection file

I am trying to determine the path to the track selected in iTunes using AppleScript. This is not like a property of the track class. Can someone tell me how can I get the file path?

+3
source share
3 answers

Try the following:

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

If you intend to use Python instead of AppleScript and don’t want to parse the XML plist 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 
+1
source

If this is not available through AppleScript, the best option would be to open and analyze the iTunes plint file. If you need only static information, you are golden. If you need dynamic information (for example, information about the track that is currently playing), you want to get a constant identifier trace through AppleScript, then parse the plist file and find any information you need (including a location that has a full path).

To parse this XML plist 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

0
source

Source: https://habr.com/ru/post/1315005/


All Articles