AppleScript optimisation

Is there a way to execute this script faster?

tell application "Daylite"
   eval "(selectedObjects lastObject) name."
end tell

tell application "Keyboard Maestro Engine"
   make variable with properties {name:"Current Object Name", value:result}
end tell

You should give more context information. And I doubt this script will work at all.

Hiya, I run this script as a KM action to run AppleScript.

As someone whose domain is not AppleScript (but who does Performance for a living) I’d observe a couple of things:

  1. At least you’re not looping - at the script level.

  2. I’d attempt to figure out which of these two statements is contributing most to the time.

Hey Ali,

Never, ever use the result variable. It makes debugging a nightmare and makes code much harder to read.

tell application "Daylite"
   set currentObjectName to eval "(selectedObjects lastObject) name."
end tell

tell application "Keyboard Maestro Engine"
   setvariable "Current Object Name" to currentObjectName
end tell

No, there’s no way to optimize this code to make it run faster.

However — you can execute it a little faster by running it from a script-file instead of a text-script.

** Script files must be saved as a Script or Script Bundle using the Apple Script Editor (or Script Debugger if you have it).

The Execute an AppleScript action gives you the option of running either a script-file or a text-script.


1 Like

Thank you.