title: Conversion of iTunes applescript to use newer iTunes library framework
body: <p>Can this applescript be converted to use the <a href="https://developer.apple.com/reference/ituneslibrary" rel="nofollow noreferrer">iTunes Library framework</a> instead of using the standard iTunes applescript . </p>
  
  <p>My current script reads the users iTunes library and creates a file consisting of TrackName, TrackLocation and PersistentId, it works reliably but can be slow when user has a large iTunes library</p>
  
  <pre><code>tell application "iTunes"
      with timeout of 2400 seconds
          if (count of every file track of library playlist 1) is equal to 0 then
              set thePath to (POSIX file "/tmp/songkong_itunes_model.new")
              set fileref to open for access (thePath) with write permission
              set eof fileref to 0
              close access fileref
              return
          end if
  
          tell every file track of library playlist 1
              script performancekludge
                  property tracknames : its name
                  property locs : its location
                  property persistids : its persistent ID
              end script
          end tell
      end timeout
  end tell
  
  set thePath to (POSIX file "/tmp/songkong_itunes_model.new")
  set fileref to open for access (thePath) with write permission
  set eof fileref to 0
  
  tell performancekludge
      repeat with i from 1 to length of its tracknames
          try
              set nextline to item i of its tracknames ¬
                  &amp; "::" &amp; POSIX path of item i of its locs ¬
                  &amp; "::" &amp; item i of its persistids
              write nextline &amp; linefeed as «class utf8» to fileref
          end try
      end repeat
  end tell
  close access fileref
  </code></pre>
  
  <p>The big different is this new framework doesn't require iTunes to actually be running and I expect it should be considerably faster. However the sparse instructions only discuss ObjectiveC I'm not clear how I would write a version in applescript (or even better in Java)</p>