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

Combine / Run 2 different scripts

Is it possible to combine two different scripts to be processed one after another?


on run

open (choose file with multiple selections allowed)

end run


set script1 to load script (alias "file")

run script script1


set script2 to load script (alias "file")

run script script2


end open



Where should I look for to combine them and to run consecutively?

Is this possible without changing the separate scripts?

Thanks in advance

Posted on May 5, 2015 1:42 AM

Reply
Question marked as Best reply

Posted on May 5, 2015 6:45 AM

Colin @ mac.com wrote:

Is it possible to combine two different scripts to be processed one after another?


As you posted, use run script

(I don't think its necessary to use load script)

You can also point to the file directly:

run script POSIX file "/Users/Tony/Library/Scripts/script1.scpt"

run script POSIX file "/Users/Tony/Library/Scripts/script2.app"

5 replies
Question marked as Best reply

May 5, 2015 6:45 AM in response to Colin @ mac.com

Colin @ mac.com wrote:

Is it possible to combine two different scripts to be processed one after another?


As you posted, use run script

(I don't think its necessary to use load script)

You can also point to the file directly:

run script POSIX file "/Users/Tony/Library/Scripts/script1.scpt"

run script POSIX file "/Users/Tony/Library/Scripts/script2.app"

May 5, 2015 11:31 AM in response to Colin @ mac.com

Hello


If the external scripts have open handler as an entry point, you can use something like the following script to invoke them.



on run open (choose file with multiple selections allowed) end run on open argv tell (load script POSIX file "/path/to/a.scpt") to open argv tell (load script POSIX file "/path/to/b.scpt") to open argv end open




provided that for instance a.scpt and b.scpt have open handler as follows.



-- a.scpt, b.scpt on run open (choose file with multiple selections allowed) end run on open argv _main(argv) end open on _main(argv) -- main code to process argv return {count argv, argv} -- e.g. end _main




Note that in the above a.scpt and b.scpt will process the same original argv.


* If you want to modify the files in argv firstly by a.scpt and then by b.scpt, you'd need to either a) have a.scpt modify the files in place, or b) have a.scpt return an alias list of modified files and have the caller script use the list in invoking open handler of b.scpt.


Regards,

H

May 6, 2015 12:39 AM in response to Colin @ mac.com

I think you're over-thinking this, or am I missing something?


If your script includes an 'on run...' handler then that code is run when the script starts. All script code must be inside this run() handler or inside another handler.


If your script does not include an 'on run...' handler then the entire script is treated as an implicit run handler and the script starts executing at the first statement.

Accordingly, in your example you have an 'on run' handler, so all statements need to be inside there, or in other handlers. e.g., either:


on run-- optional if all statements are to be executed


open (choose file with multiple selections allowed)


set script1 to load script (alias "file")


run scriptscript1


set script2 to load script (alias "file")


run scriptscript2


end run



Or the other statements must be moved to a different handler:


on run-- optional if all statements are to be executed


open (choose file with multiple selections allowed)


doSomeOtherStuff


end run


on doSomeOtherStuff()

set script1 to load script (alias "file")


run scriptscript1


set script2 to load script (alias "file")


run scriptscript2


end doSomeOtherStuff

Combine / Run 2 different scripts

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