Reputation: 13210
Can I use Applescript to find the current iTunes media location and other iTunes options.There doesnt seem to be such options when I read the iTunes Applescript Dictionary within Script Editor but surely there is a way to do it.
I read in the past that something is stored in com.itunes.plist but its not plaintext and my plist file did not change when I created a new libary so Im not convinced it is still used, or if it is kept up to date.
Upvotes: 3
Views: 585
Reputation: 1347
Yes, @PaulTaylor, you can get the media folder location of the current user in AppleScript using the Apple-provided iTunesLibrary framework. (documentation at iTunesLibrary at Apple)
Here's a working AppleScript to do it:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "iTunesLibrary"
set lib to current application's ITLibrary's libraryWithAPIVersion:"1.0" |error|:(missing value)
set mediaFolderPath to POSIX path of (lib's mediaFolderLocation as alias)
--> "/Volumes/LaCie 6/iTunes Library/"
Upvotes: 2
Reputation: 3722
The media location is not saved in the global iTunes preference file. Because you can have multiple libraries, and each library defines its own media location, this is actually saved in the the library preferences. The default library is located at ~/Music/iTunes/iTunes Library.itl
. I'm not sure what kind of file this is. It does not seem to be a plist/xml file, nor an sqlite file. It seems to just be a proprietary binary file.
Inside the same folder, I also found iTunes Music Library.xml
(after some testing around, that file is now missing, so YMMV for the rest of this explanation). Here is a truncated example:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Major Version</key><integer>1</integer>
<key>Minor Version</key><integer>1</integer>
<key>Application Version</key><string>12.3.3.17</string>
<key>Date</key><date>2016-04-14T19:35:27Z</date>
<key>Features</key><integer>5</integer>
<key>Show Content Ratings</key><true/>
<key>Library Persistent ID</key><string>1AEAB6C2057C2167</string>
<key>Tracks</key>
<dict>
</dict>
<key>Playlists</key>
<array>
</array>
<key>Music Folder</key><string>file:///Users/<username>/Music/iTunes/iTunes%20Media/</string>
</dict>
</plist>
Note the key Music Folder
. This is the setting you are looking for to find the library's media location. There are also some library settings, such as a list of playlists and track information.
Upvotes: 0