osx - Get path to main iTunes library and play a song from it -


i have applescript lets type in song , play it.

here is:

    set userinput text returned of (display dialog "type something" default answer "") if userinput contains "play "     set {tid, text item delimiters} {text item delimiters, {"play "}}     if length of userinput greater or equal 2 set resultstring text item 2 of userinput     set text item delimiters tid     set playsong (resultstring string)     tell application "itunes"         set mysongs every track of library playlist 1 name playsong         repeat asong in mysongs         play asong         end repeat          if (count of mysongs) = 0             "song not found"         end if     end tell end if 

basically, need path main itunes library , play song it. currently, search songs, itunes has open. , if can't find song, stays open. want search actual itunes directory make if itunes cannot find song, doesn't open

i have no idea how this.

thanks

here script search in "itunes library.xml" file.

set xmlfile get_itunes_library_xml() set userinput text returned of (display dialog "type something" default answer "play ") if userinput begins "play " , length of userinput > 5     set playsong text 6 thru -1 of userinput     set searchstring "<key>name<\\/key><string>" & playsong & "<\\/string>" --  match exact name      if (my searchtrackname(searchstring, xmlfile)) not ""         tell application "itunes" play (tracks name playsong)     else         "song not found"     end if end if  on searchtrackname(t, f) -- search in itunes library.xml file     if "&" in t set t shell script "sed  \"s/&/&#38;/g\" <<<" & quoted form of t -- replace "&" "&#38;"     try -- return count of matching lines         return shell script "grep -c -m1 -i " & (quoted form of t) & " " & f -- "-i" equal case insensitive, "-m 1" exit @ first match     end try     return "" end searchtrackname  on get_itunes_library_xml() -- path     shell script "defaults read com.apple.iapps itunesrecentdatabases | sed -en 's:^ *\"(.*)\"$:\\1:p' |/usr/bin/perl -muri -e 'print uri->new(<>)->file;'"     return quoted form of result end get_itunes_library_xml 

the "com.apple.iapps.plist" file contains path yours itunes libraries (if have more one), script path of "itunes library.xml" file of current library.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -