FastScripts 3.2 featuring customized script folders and parameterized scripts

I just posted FastScripts 3.2 with a number of pretty major improvements, including a couple power-scripter type features that I think will be of interest particularly to this group. You can read more here:

In particular the ability to pass parameters to scripts AND to wait for the result of the scripts. Unlike Apple’s default “run script” command, I’ve separated out the run action from the “wait for the result” request, so you can do some creative things queuing up jobs for FastScripts to perform and then wait for all of them to complete.

Let me know if you have any feedback! Thanks,

Daniel

7 Likes

What a fantastic upgrade, Daniel! You’ve taken FastScripts in a really great direction.

I’ve only been using FastScripts since version 3.0 came out, but it’s already become indispensable to me. It takes a lot of the hassle out of running AppleScripts.

1 Like

One of the really powerful usecases is that FastScripts can now be used as a replacement for osascript from the command line! This lets you use FastScripts’ superior script runner and error/progress reporting from anywhere in macOS. Nice!

It also makes storing .scpt files in iCloud Drive a little saner, as FastScripts doesn’t modify the .scpt file after running (unlike osascript), so you don’t end up with modifications getting out of sync.

Shell script (fastscripts.sh) for running AppleScripts from the command line:

osascript -e 'on run argv
	if length of argv is 0 then error "usage: fastscripts.sh <path>" number 2
	tell application "FastScripts" to return result of (run (item 1 of argv as «class furl») with parameters (rest of argv))
end run' "$@"

Invoked as: fastscripts.sh /PATH/TO/SCRIPT arg1 arg2

3 Likes

Great thinking @tree_frog! Thanks for sharing.

1 Like

Daniel - Thank you very much for FastScript’s and it’s continuing development. I am already thinking of uses for the new ability of running scripts. I wish all applications were of its caliber.

1 Like

Is there any documentation for this?

Are there any other solid alternatives to using osascript to execute appleScripts from a SwiftUI app?

Daniel (@redsweater) has documented his AppleScript API in his release notes, and the scripting dictionary for FastScripts is thorough.

My post above just uses /usr/bin/osascript to bridge the shell to FastScript’s AppleScript API.

Some notes since posting the above:

  • The run command used here is defined by FastScripts, and is not the same four-character code as the run event used elsewhere. For this reason, FastScript now makes it a synonym for invoke, which is less ambiguous.
  • It’s useful to extend the timeout beyond AppleScript’s default 120 seconds, for longer-running scripts.

For performance reasons, it’s best to have osascript use a pre-compiled AppleScript rather than having to compile it from a string every time. So, an updated answer is:

  1. Save the ‘trampoline’ AppleScript somewhere…
    on run argv
    	if argv is me then set argv to {}
    	if length of argv is 0 then error "usage: fastscripts <path>" number 2
    	with timeout of 3600 seconds
    		tell application "FastScripts"
    			return script result of (invoke (item 1 of argv as «class furl») with parameters rest of argv)
    		end tell
    	end timeout
    end run
    
  2. …and run it from the shell using:
    osascript /path/to/trampoline.scpt /path/to/script.scpt [arguments]
    

To my knowledge, this is the best way to run AppleScripts as an end-user, in an environment that you can control, where you can ensure that FastScripts in installed, configured, and running. The big benefit with this approach is FastScript’s performance with AppleScript-Objective C scripts.

If you’re developing an application where you can’t guarantee that FastScripts is available, you either have to do your own NSAppleScript/NSUserAppleScript implementation (see also Running AppleScripts through the ScriptMonitor.app Utility), or use osascript (and accept forced script persistence & slow ASOC startup).

Thanks, and thanks for the link. The issue I have with osascript is not being able to execute scripts that use third party frameworks, like Myriad Tables.