Auto-compile/codesign/export AppleScripts to compiled, read-only .scpts

Steps to reproduce:

Running AppleScript uncompiled

  • Create a new action as Run Apple Script (blocking) and Source type: Applescript,
    for example with this script pasted directly in the BTT script window:
set appName to "Finder"
set startIt to false
tell application "System Events"
	if not (exists process appName) then
		set startIt to true
	else if frontmost of process appName then
		set visible of process appName to false
	else
		set frontmost of process appName to true
	end if
end tell
if startIt then
	tell application appName to activate
end if

Use a timer and benchmark how fast it runs to completion.

Running AppleScript compiled, code-signed and written to disk

Open the same script in Apples Script Editor.app

  • Export >> File Format: Script (.scpt) with options:
    • Code Sign(use your Apple Development profile)
    • run-only
  • Save somewhere as your_script.scpt

Reconfigure your trigger to Run Apple Script (blocking) but with `Source Type: Apple Script From SCPT file"

Benchmark again. No surprise it runs so must faster, but also starts so much faster. No lag.

A: a possibility for BTT to automate this? (compile, code-sign, save, re-import to BTT action)
or
B: any way for me the end user to automate this somehow?

Keep up the great work!

BTT works great on Catalina now with the recent builds.

When using the async option BTT compiles every script and stores it in-memory, however the first run after restarting BTT will do a new compile and probably be slower. I think the code signing won't make it faster.

I'll check, maybe I can add an option to store the compiled versions somewhere and always load them.

Awesome!

  • Now I just found the feature "show/hide specific app" and that it almost replace the scripts I had (inspired by Brett Terpstra) to toggle application visibility and launch the app if not running. And it is way faster then dispatching to applescript.
  • Only thing it lacks is to see whether the app has any windows or not, and if not, create a new. Perhaps I should add it as a feature request, if people think it is a natural addition to the already exisiting functionality?