2

This script works okay for me and most of my customers, but for a few customers it times out with error -1712; I've no idea why. I've tried increasing timeout, but it makes no difference.

The file /tmp/itunes_model.txt doesn't get created so it doesn't seem to be doing anything.

How can I debug/fix this?

with timeout of 1200 seconds
tell application "iTunes"

    if (count of every file track of library playlist 1) is equal to 0 then
        set thePath to (POSIX file "/tmp/itunes_model.txt")
        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 tell

set thePath to (POSIX file "/tmp/itunes_model.txt")
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 ¬
                & "::" & POSIX path of item i of its locs ¬
                & "::" & item i of its persistids
            write nextline & linefeed as «class utf8» to fileref
        end try
    end repeat
end tell
close access fileref
end timeout

Added a try-catch around the error as requested and reran; the first time it was run it actually worked which is interesting, but the second time it failed again gleaning no more useful information.

enter image description here

6
  • Can you put a try, on error err, display dialog err, end try into the code to get a report back from them with more data than the error number?
    – jweaks
    Nov 7, 2015 at 4:32
  • could you show me how I dont really know Applescript Nov 8, 2015 at 16:19
  • It's hard to show code in comments. You really can google for examples. Put a line after 'with timeout' that says: "try" then before 'end timeout', put three lines: "on error err' 'display dialog err' 'end try'
    – jweaks
    Nov 9, 2015 at 5:54
  • I did as you said and got him to run again and it seemed to actually work with no error, which makes little sense. I'll report back when I have more information Nov 11, 2015 at 8:17
  • @jweaks Ive now as you requested, the script actually worked once but now failing as before with no additional info Nov 17, 2015 at 8:30

1 Answer 1

2

It should something like this:

tell application "iTunes"
    with timeout of 1200 seconds
    ...
    end timeout
end tell

Your timeout should be inside the tell block instead before/above/outside of it.

It seems as if you might be setting the timeout for the script itself instead of iTunes which has a default timeout of 120 seconds (all applications have a default timeout of 2 minutes).

This could be failing for a number of reasons besides normal timeouts, such as if the person just upgraded iTunes, and your script opens it for the first time after it was recently installed, it won't be able to execute normal iTunes functions until after closing out of the splash screen that says "Welcome to iTunes version X - Check out all of the new features!, etc."

Also, it's been awhile since I've worked with AppleScript, so I don't recall whether or not if you tell a system application to do something if it automatically opens or not. If not, it's possible, you may need to Tell SystemEvents to open application "ITunes" (or whatever the syntax is) -- or you could always use the do shellscript command to open the application, in which case the actual shell command would be open /Applications/iTunes.app/ -- which you can verify in Terminal.

The error could also be if the iTunes app needs GUI focus for these operations to take place and the application automatically loses focus while the script is being run when another application is opened or the user clicks away or some scenario of that sort, which your script will need to be able to account for. In cases such as this, you may want to tell SystemEvents to activate application "iTunes" before any important actions take place. This will cause the iTunes window to regain focus.

It may actually be this same SystemEvents command (you probably need to check/correct my syntax) that initially opens the application if it is not already open at the time the script is run.

1
  • ooh if you are right about the timeout that would be great, Ive sent amended script to user to try Dec 2, 2015 at 12:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .