Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

call another applescript

i need to move a section of code from an existing applescript into a new script, and then call that script file from within the original script - if that isnt too confusing...!! 😉

but more generally, it would be good to know how to call another applescript from inside an applescript. have tried "do script "path/to/file.scpt" and "run script "/path/to/file.scpt"

regards

jingo_man

iMac 20", Mac OS X (10.5.2)

Posted on Apr 14, 2008 10:23 AM

Reply
Question marked as Best reply

Posted on Apr 14, 2008 10:41 AM

'do script' isn't a valid command, so that won't work. You might be thinking of 'do shell script', but that runs a shell script, not an AppleScript.

You have several options.

do shell script
You can use 'do shell script', using osascript, which is the command-line method to run an AppleScript:

<pre class=command>do shell script "osascript /path/to/file.scpt"</pre>

That is cumbersome, though - AppleScript launching a shell, to run an AppleScript...

run script
You can run a script directly, but you need to provide a Mac-style path to the script, not a unix-style path:

<pre class=command>run script "HD:path:to:file.scpt"</pre>

(you can use POSIX file to coerce a Unix path into a Mac path/alias)

load script
You can also load the script into memory and call it within your script. For example, this snippet will load a script from disk and then call the 'handlerName()' function within it (as opposed to the others that only call its run handler):

set myScript to load script "HD:path:to:file.scpt"
set scriptResult to myScript's handlerName()
4 replies
Question marked as Best reply

Apr 14, 2008 10:41 AM in response to jingo_man

'do script' isn't a valid command, so that won't work. You might be thinking of 'do shell script', but that runs a shell script, not an AppleScript.

You have several options.

do shell script
You can use 'do shell script', using osascript, which is the command-line method to run an AppleScript:

<pre class=command>do shell script "osascript /path/to/file.scpt"</pre>

That is cumbersome, though - AppleScript launching a shell, to run an AppleScript...

run script
You can run a script directly, but you need to provide a Mac-style path to the script, not a unix-style path:

<pre class=command>run script "HD:path:to:file.scpt"</pre>

(you can use POSIX file to coerce a Unix path into a Mac path/alias)

load script
You can also load the script into memory and call it within your script. For example, this snippet will load a script from disk and then call the 'handlerName()' function within it (as opposed to the others that only call its run handler):

set myScript to load script "HD:path:to:file.scpt"
set scriptResult to myScript's handlerName()

Apr 14, 2008 7:37 PM in response to jingo_man

Hello

You get that error message because you're actually trying to run the path string itself.

E.g.
The next line works because command's argument is text consisting of valid script source:
run script "display dialog \"woohoo\""

But the next line won't work because command's argument is not valid script source:
run script "Macintosh HD:Users:<username>:Documents:woohoo.scpt"



You should have written:
run script file "Macintosh HD:Users:<username>:Documents:woohoo.scpt"

or:
run script ("/Users/<username>/Documents/woohoo.scpt" as POSIX file)

Cheers,
H

call another applescript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.