Use Applescript to launch multiple instances of an application
This is my code. I wanted to run an app (Game Capture HD.app) twice at the same time. But I get this Syntax Error: Expected “"” but found unknown token.
on run
do shell script "open -n /Applications/Game\ Capture\ HD.app"
tell application "Game\ Capture\ HD" to activate
end run
on open theFiles
repeat with theFile in theFiles
do shell script "open -na /Applications/Game\ Capture\ HD.app " & quote & (POSIX path of theFile) & quote
end repeat
tell application "Game\ Capture\ HD" to activate
end open
Solution 1:
The spaces mess things up. Try:
do shell script "open -n " & quoted form of "/Applications/Game Capture HD.app"
Essentially, 'quoted form' is for passing text to 'do shell script'. Both the Script Editor and the shell will be interpreting the text and 'quoted form' helps manage that.
Save the following as an application and then if you drop some text files on it, a separate instance of TextEdit will open each. The app and each of the dropped files get wrapped in single quotes for the shell.
on open theFiles
set tApp to "/Applications/TextEdit.app"
set qApp to quoted form of tApp
repeat with ef in theFiles
set ppf to quoted form of POSIX path of ef
do shell script "open -n " & qApp & space & ppf
end repeat
end open
To see how it breaks down, here it is as a regular script that works with selected files. The set shCmd…
line returns the command sent to the shell.
tell application "Finder" to set theFiles to selection as alias list
set tApp to "/Applications/TextEdit.app"
set qApp to quoted form of tApp
repeat with ef in theFiles
set ppf to quoted form of POSIX path of ef
do shell script "open -n " & qApp & space & ppf
set shCmd to "open -n " & qApp & space & ppf
--> "open -n '/Applications/TextEdit.app' '/Users/username/Desktop/style attributes of.rtf'"
end repeat
To use with a different app, change the value of 'tApp'.