Tuesday, October 29, 2013

Mavericks and AppleScript’s “exists process”

Dave Nanian notes that running an AppleScript that asks System Events merely whether a process is running brings up the new accessibility permissions dialog. This has caused some problems for SuperDuper. Unfortunately:

5 Comments RSS · Twitter

There's also 'application "XXX" is running', which was added in 10.5. It looks like SuperDuper! still works back to 10.4.11 so that may not be an option, but I'd say that's pretty extreme backwards compatibility these days.

http://www.macosxautomation.com/applescript/features/appobject.html

@Nicholas Good tip; thanks.

[...] Tsai in his blog pointed to a detailed discussion at Mac OS X Automation on Accessibility Preferences and GUI [...]

"This is the documented and most straightforward way to check whether an application is running."

I assume SuperDuper is written in ObjC, in which case why isn't it using the appropriate Cocoa method** to check if a user process is running:

[NSRunningApplication runningApplicationWithProcessIdentifier:@"com.example.yourapp"]

Much more straightforward than messing about with System Events and AppleScript.

(**Prior to 10.6, IIRC, checking for a running process required calling -[NSWorkspace launchedApplications] then filtering the resulting NSArray for a match, tho' still simpler than messing about with NSAppleScript.)

@has SuperDuper is written in Objective-C, but for reasons that I don’t understand it implements scheduled jobs via a separate applet.

Leave a Comment