Embed AppleScript

Is it possible to call another applescript from within an applescript? I’ve searched and found nothing other than to write a shellscript and the use osascript to call the applescript and then call the shell script in the applescript. Are you still following me? I know there has to be an easier way to do it. Thanks

No :wink:

Hi Dave.
Welcome to MacScripter

It’s quite easy:

run script alias "MacHD:Users:myUser:path:to:myScript.scpt"

Hi Dave;

A script can also be embedded in another one:

script o
	property y : 2
	to makeChoice()
		set x to choose from list {1, 3, 4}
	end makeChoice
end script

set L to {"A", "B", "C", "D"}
set K to {"e", "f", "g", "h"}
return item (o's makeChoice()) of L & item (o's y) of K


I have been using ‘load script’ instead of ‘run script’ to accomplish the same thing. What if anything is the functional difference between the two?

A loaded script is easier to reuse (run script would have to read the file again) and your script would be able to access all the parts of the loaded script (e.g. properties and multiple handlers). On the other hand, it can be helpful to just pass another script from parameters and let it run without worrying about what else is going. (Also, for a one time use, run script might be considered more efficient in that it doesn’t stay loaded after doing it’s thing.)

Load script is mostly used for (what are called) library scripts. An example would be a script that has a sort routine that you want to be able to use in more than 1 script, so you make it a “library script” and load it at the beginning of any of your other scripts that need a sort routine.

Run script is used (as pointed out already) when you need to run a script but don’t need to rerun the script very often. For example, you could write a script that creates a list of scripts and allows the user to run one by selecting it using choose from list.

Hopefully this answers your question. If you need help, post back and we’ll see what we can do! :slight_smile:

Interesting. Thanks to your info I now realize that 80% or so of the ‘load script’ calls I have used should probably be rewritten as ‘run script’ to free up resources. Live and learn. :smiley: