AppleScripts run a bit faster when saved as pre-compiled .scpt files than when run as text scripts via Keyboard Maestro.
The following macro will use the text script of the currently selected Execute an AppleScript action to create a .scpt file. It will then add a new action to your macro that executes this file.
Also, if I edit them and want to save them, it does not allow me to do so. I have to do Save As and replace the existing file. Any work arounds for that? (click to expand/collapse)
Looking at the osacompile man page (osacompile Man Page - macOS - SS64.com) it would seem to me that you can`t compile a file into itself which is what you’re trying to do.
Hey @noisneil the macro is working great. Quick question: would it be possible to either remove the script text from the pasted action, or set that as an option? The pasted action still contains the script if you switch it from “Execute script file” to “Execute script text”, and removing the text would cut down on the macro size which is another benefit for macros with large/complex AppleScripts.
I've been hesitant to remove the text from the action, in case there's an issue (e.g. we accidentally overwrite the script file during macro testing) and we want to be able to access the text version again. Same reason I've been disabling rather than removing the original action.
What happens when we share a macro that relies on these external scripts and we've deleted the text version? It's all a bit anxious-making!
In an ideal world, it would convert every AppleScript action in the current macro. If you run it again it would convert them back. These functions could also be incorporated into our upload macro, checking for potential orphaned scripts before converting (and then converting back after upload if necessary).
...or alternatively, the upload macro could check for any file paths ending in .scpt in the macro XML, zip these files together and include them in the upload...
Or... we could just be a bit careful about which macros get the script conversion treatment...
Or alternatively you could run osadecompile on the compiled script to get back to the text. If you do that you may want to research into the possible drawbacks of using that shell command…
If you run the macro with a script file version of the action selected, it will convert it back to a text version and tidy up your compiled scripts folder by deleting the script file and trashing its parent folders if they are empty.
The reason I've decided not to decompile and remove the text from the action is that a 10,000 character script takes up only 10KB, and I'd rather maintain that text as a backup in case a user's compiled scripts folder goes walkabout for some reason.
It also means that, when sharing macros, the recipient can switch the actions to use text and still have a working macro.