0

I have an applescript that I've been working on the past week or so. I've been running & rerunning a script, fixing bugs, etc. that are deep in the code. Sometimes, the script would take a really long time at a certain step, or even make the script editor unresponsive. In those instances, I was forcing the editor to quit and starting it back up to add some debug statements or try a trick to make it faster.

Well, at some point today, I tried to run the script after a force-quit, and it started randomly hanging in a loop at the top of the script that I had not touched for weeks. All the loop does is repeat on a list and append values to a string - simple. Yet, it hangs somewhat randomly in that loop each time I try to run it. It will hang on the same loop iteration (e.g. on iteration 2446) if I don't edit the code - but if I edit & rerun, it hangs in a different place. When I added a dialog to a specific iteration where I thought it was consistently hanging, it made it all the way through the loop without a hang. I removed the dialog and it hung again on a different iteration...?! There's no reason that I can see why it should be hanging at this point early in the script. I tried restarting the computer, yet it still would hang somewhere in that first loop.

I downloaded "Script Debugger 5" and tried running the script from it... no more hangs! So I'm starting to think that something happened to the Applescript Editor - perhaps from my various force-quits?

  1. Is my intuition correct - that the Editor is somehow corrupted?
  2. If the Editor is corrupted, how do I repair it?

Here is the loop (it's the first one) that hangs on a random loop iteration. There's very little code above it, which is simple and has not changed in months.

tell application "Contacts"
        try
            --with timeout of 5 seconds
            set myEmails to value of first email of every person
            set allemailsstr to ""
            set myPhones to value of first phone of every person
            set allphonesstr to ""
            repeat with m from 1 to count of myEmails
                if (item m of myEmails as string) is not "missing value" then
                    tell application "ASObjC Runner"
                        --with timeout of 1 second
                        set properties of progress window to {detail:"Collecting Email " & m & " of " & (count of myEmails) & " and Phone 0 of " & (count of myPhones)}
                        --end timeout
                    end tell
                    set allemailsstr to allemailsstr & item m of myEmails & "
"
                end if
            end repeat
            repeat with m from 1 to count of myPhones
                if (item m of myPhones as string) is not "missing value" then
                    tell application "ASObjC Runner"
                        with timeout of 1 second
                            set properties of progress window to {detail:"Collecting Email " & (count of myEmails) & " of " & (count of myEmails) & " and Phone " & m & " of " & (count of myPhones)}
                        end timeout
                    end tell
                    set allphonesstr to allphonesstr & item m of myPhones & "
"
                end if
            end repeat
            --set the clipboard to allemailsstr
            --end timeout
        on error errStr
            display dialog "Encountered a timeout while simply adding people to a list"
        end try
    end tell

I can post the code above if requested, but like I said, it's really simple - just some variable declarations, the setup of the GUI progress bar, and a couple dialog windows. The number of contacts it is repeating on is over 8K.

FYI, the commented timeout code was not catching the hangs. When the hangs occur, the editor is unresponsive. This is a long-running script, measured in hours.

UPDATE: I no longer think that the Applescript Editor is corrupted somehow. I suspect that it may be some sort of memory limit (or some other limit). Here's why. When I run the same script in Applescript Editor on a different computer (my work computer), I still get a hang. Script Debugger still does not hang.

  • Oh yeah, I had suspected Contact.app's communications with icloud to be a part of the problem, since I'm about out of icloud disk space, so I tried running without a connection to the internet with the same result. I was able to run it offline successfully before, so I think I have effectively ruled out an icloud issue. – hepcat72 Jan 10 '16 at 21:47
  • Well, Script Debugger 5 can run the entire script without a hang or an error. It completed in 3 hours, 55 minutes, and 40 seconds. 98% of the time, it was waiting on the contacts application. So why can't the Applescript Editor run it without hanging? – hepcat72 Jan 11 '16 at 1:20
  • Try commenting out most of the codebase (use '(* *)' comments to make it quicker ;), and see if the resulting code hangs. If not, start uncommenting things until the issue occurs again, and we'll have an idea of what's causing the issue. – William T Froggard Jan 26 '16 at 2:50

You must log in to answer this question.

Browse other questions tagged .