Joe Maller.com

More on the System Events AppleScript bugginess

After a ton of testing and waves of frustration, I think this is finally ready to test again.

UIcheck() System Events Test Script 2 (UIcheck-100605-1525.zip, 10k)

Again, please run this and let me know what your results are, including OS version and a vague hardware description.

A few observations:

The script is much larger, but the re-useable parts are fairly self-contained. Most of the size comes from error logging and timing functions. Please feel free to pilfer whatever you want from this example.

One of the biggest problems noted by the previous test script was -609 “Connection is invalid” errors. Thanks to a great post and followup by Bill Cheeseman on the CocoaBuilder site, I figured out why those were happening.

Essentially, AppleScript was sending commands to an application which wasn’t ready yet or that was shutting down. For whatever reason, AppleScript doesn’t necessarily clear the reference to an application that’s been sent a quit command. It’s possible, and quite likely that sending a command to an application immediately following a quit command won’t restart the application, it will cause a -619 connection error since AppleScript will try to send the command to the vanishing application.

Additional testing proved that hypothesis. Several other applications all threw -619 errors when cycled too quickly. So these errors weren’t the issue. There were still occasional “-50 Parameter error” errors, which seem to occur randomly whenever sending a command to System Events. These appear to be the most traceable problem I’ve found.

That noted, System Events seems incredibly slow to quit. On 10.3.9 it requies two tries almost every time. After testing some delay statements to pause the script, I ended up looping around a try statement which quits and re-launches the application. If the application responds correctly, the try doesn’t fail and the repeat is exited.

Hopefully this will continue to work. In testing I found the scripts seems sensative to humidity, mean looks, cute girls and smelly lunches. They’d work one day and fail inexplicably the next. This iteration however, seems to be working.

The next step is to build in an error-catching loop into the iPhoto date setting routines to make sure the script doesn’t fail and skip over any photos.

Previous posting on this topic is here: AppleScript System Events Bug

Update Thanks to everyone who helped test this, I’ve rolled these functions into my iPhoto AppleScripts which should be more robust now.


5 Responses to “More on the System Events AppleScript bugginess” Comments Feed for More on the System Events AppleScript bugginess

  • when it worked it failed 0 times of 100. went out of sync 0-29 times but it was handled correctly. took about 30 secs.

    of about 8 tests it got a ‘script timeout’ about 4 times though.

    it was being run through script editor…
    I’m on osX tiger.

  • no ‘script timeout’s here.

    Trial 1:
    failed 0 for 100
    0 sync errors
    30 seconds

    Trial 2:
    failed 0 for 100
    1 sync errors
    31 seconds

    Trial 3:
    failed 0 for 103
    47 sync errors
    33 seconds

    Trial 4:
    failed 0 for 100
    1 sync errors
    30 seconds

    Trial 5:
    failed 0 for 101
    3 sync errors
    32 seconds

    Trial 6:
    failed 0 for 100
    0 sync errors
    29 seconds

    Mac OS X 10.4.2, AL Pbook 1.25, 1 GB RAM, iPhoto 5.0.4
    Good Luck! Hope this little bit helps.

  • Trail 1 :
    failed 0 times for 103 attempts
    out of sync 8 times but handled correctly
    51 seconds

    trial 2:
    failed 0 of 100 times
    out of sync 2 times but handled correctly
    42 seconds

    10.4.2 tibook 1ghz 1gb ram
    thanks again,
    tim

  • failed 0 for 100
    0 sync errors
    34 seconds

Leave a Reply