I’m trying to use iCollections as an AppleScript launcher. As it is, it simply opens a compiled AppleScript file in Script Editor. With option down, it is capable of opening a file with a specified application. So I wonder if there exists an app that runs an AppleScript file when it is called?
You can create a stay-open standalone app with script editor that will call and execute other scripts.
Do you need it to always run the same script, or have it ask you for a script, or you can also have it use drag & drop
Here is a sample…
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
on run
local myScript
set myScript to choose file with prompt "Choose an AppleScript file to execute…" of type {"com.apple.applescript.script"}
run script myScript
end run
on open fnames
local typeID, fname
repeat with i from 1 to count fnames
tell application "System Events" to set {typeID, fname} to {type identifier, name} of (item i of fnames)
if typeID = "com.apple.applescript.script" then
run script (item i of fnames)
else
beep
display alert "ERROR, File \"" & fname & "\" is not a script file!" giving up after 5
end if
end repeat
end open
Save this as a stay-open standalone app
Thank you for your help and the sample code. I have set up iCollections so that option-clicking a file will open it in my custom AppleScript launcher!
The app will try to open all types of files in the launcher, but it can be tolerated.
I have been looking for a replacement for DragThing, and I can now execute AppleScript files with one click on an icon on a floating window.
FYI, I use a stay-open app running Shane’s Myriad Tables (and another using Dialog Toolkit Plus with Myriad Tables) to do the same thing.
It simply displays a list of scripts, apps (or handlers), and when the user double clicks it launches the script then returns to the list.
I can post if interested.
I’d recommend:
if typeID contains "applescript" then
as "com.apple.applescript.script"
is the uniform type identifier specific (I think) to compiled scripts (which, to be fair, is what the OP wanted, but it’s not a necessary requirement for what he wants or what your app does). You could, of course, obtain the UTI for AppleScript text files, which I can’t recall off-hand, and then test for both individually, in case there are other UTIs that contain the term “applescript” (I dont think there are, as JavaScript for Automation text files identify as any JavaScript file does).