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
		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

  • 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)
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.