1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

iTunes Media Folder

Discussion in 'iTunes & AppleScripts' started by UKenGB, Dec 11, 2015.

  1. UKenGB

    UKenGB Member

    Can I get the name of the above in an AppleScript?

    I cannot find any reference to either this or the library file location in the iTunes dictionary, but it would seem obvious to me that it should be possible to obtain these paths for use in scripts. What's the best way to get the path to the Media Folder?
     
  2. DougAdams

    DougAdams Moderator Staff Member

    This is available in the XML file using the key "Music Folder". So, get the location of the XML file from the iApps.plist file, and parse the XML. So you can do something like this:


    use AppleScript
    use framework "AppKit"

    set currentXMLPath to ((((current application's NSUserDefaults's standardUserDefaults()'s persistentDomainForName:"com.apple.iApps")'s objectForKey:"iTunesRecentDatabasePaths")'s objectAtIndex:0)'s stringByExpandingTildeInPath()) as text

    tell current application's NSMutableDictionary to set itunesLibraryXML to its dictionaryWithContentsOfFile:currentXMLPath

    set mediaFilePath to (((current application's NSURL's URLWithString: (itunesLibraryXML's objectForKey:"Music Folder"))'s |path|())) as text
     
    Last edited by a moderator: Dec 11, 2015
  3. kirk

    kirk Administrator Staff Member

    Doug, I edited your post to use a fixed-width font. It doesn't look great, but I think it's better. (Tell me if you mind my meddling...)

    Related, I need to figure out a way for code to display better here...
     
  4. DougAdams

    DougAdams Moderator Staff Member

    Yeah, I was using the BBCode Editor, but then I forgot how to do CODE with it. Been a long time.
     
  5. kirk

    kirk Administrator Staff Member

    There's a font button in the toolbar; you can choose from a number of font families. But I'll see if I can CSS something a bit better.
     
  6. UKenGB

    UKenGB Member

    Thanks Doug, I was hoping to avoid having to find the XML library and parse that. Obviously not. Here's my shell script version:-

    TXMLF=$(defaults read com.apple.iApps iTunesRecentDatabases | grep file | cut -c 13-);eval 'grep -i "Music Folder" "'${TXMLF//\%20/\ } | cut -d '/' -f 4- | cut -d '<' -f 1

    A bit messy to say the least. I had hoped to reduce the number of pipes, but it's getting late. Just need to decide now which to use.
     
  7. DougAdams

    DougAdams Moderator Staff Member

    Yeah. I used to use something along those lines but, as you say, so unpretty.
     

Share This Page