How Can I Open AppleScript App with Arguments
I Have an AppleScript that runs a Scan Program (commandline) that scans to a specific folder. I need to pass arguments to the applescript that in-turn passes the arguments to the terminal.
In a terminal I want to run open -a /Applications/MyScanApp.app myargument
and the AppleScript runs. How can I pass that argument? Thank You for Your Help! I am normally a PHP programmer and this is something completely different to me.
My AppleScript:
tell application "Terminal"
do script "./myscanprogram myargument 2>&1"
end tell
bash terminal applescript
add a comment |
I Have an AppleScript that runs a Scan Program (commandline) that scans to a specific folder. I need to pass arguments to the applescript that in-turn passes the arguments to the terminal.
In a terminal I want to run open -a /Applications/MyScanApp.app myargument
and the AppleScript runs. How can I pass that argument? Thank You for Your Help! I am normally a PHP programmer and this is something completely different to me.
My AppleScript:
tell application "Terminal"
do script "./myscanprogram myargument 2>&1"
end tell
bash terminal applescript
add a comment |
I Have an AppleScript that runs a Scan Program (commandline) that scans to a specific folder. I need to pass arguments to the applescript that in-turn passes the arguments to the terminal.
In a terminal I want to run open -a /Applications/MyScanApp.app myargument
and the AppleScript runs. How can I pass that argument? Thank You for Your Help! I am normally a PHP programmer and this is something completely different to me.
My AppleScript:
tell application "Terminal"
do script "./myscanprogram myargument 2>&1"
end tell
bash terminal applescript
I Have an AppleScript that runs a Scan Program (commandline) that scans to a specific folder. I need to pass arguments to the applescript that in-turn passes the arguments to the terminal.
In a terminal I want to run open -a /Applications/MyScanApp.app myargument
and the AppleScript runs. How can I pass that argument? Thank You for Your Help! I am normally a PHP programmer and this is something completely different to me.
My AppleScript:
tell application "Terminal"
do script "./myscanprogram myargument 2>&1"
end tell
bash terminal applescript
bash terminal applescript
edited Feb 21 '18 at 20:42
kenorb
65.3k27396392
65.3k27396392
asked Mar 25 '15 at 14:13
T VarcorT Varcor
14018
14018
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Why doesn't anyone mention quoted form of
? When you want to send arbitrary data as an argument to an application you should use quoted form of. When quotes, spaces and other special characters are in the given path the command will break down in de previous examples.
on run argv
tell application "Terminal"
do script "./myscanprogram " & quoted form of (item 1 of argv) & " 2>&1"
end tell
end run
Since you mentioned you're new to AppleScript does it have to run in the Terminal.app or is a shell enough? AppleScript has the command do shell script
which opens a shell, execute the text and return the stdout back to you.
on run argv
do shell shell script "/path/to/myscanprogram " & quoted form of (item 1 of argv) & " 2>&1"
end run
Last but not least. If you don't want the output of the scan program and don't want AppleScript to wait until it's finished you can use
on run argv
do script "/path/to/myscanprogram " & quoted form of (item 1 of argv) & " &>/dev/null &"
end run
1
Yes, you're right. I had a strange fear of quoting the arguments twice, because you have to quote your input if it contains spaces. Otherwise the argument could be parsed as two arguments instead of one. BUT: I tested it and the savest way is the use ofquoted form
indeed and it works if the shell argument is already quoted, too! ;-) thumbsup
– ShooTerKo
Mar 27 '15 at 10:13
add a comment |
Wondering why you're using your Terminal to address an AppleScript that uses the Terminal again, but maybe I just don't know your circumstances...
Applescript:
on run argv
tell application "Terminal"
do script "./myscanprogram " & (item 1 of argv) & " 2>&1"
end tell
end run
Call from osascript inside your Terminal:
osascript pathToYourScript.scpt myargument
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f29258142%2fhow-can-i-open-applescript-app-with-arguments%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Why doesn't anyone mention quoted form of
? When you want to send arbitrary data as an argument to an application you should use quoted form of. When quotes, spaces and other special characters are in the given path the command will break down in de previous examples.
on run argv
tell application "Terminal"
do script "./myscanprogram " & quoted form of (item 1 of argv) & " 2>&1"
end tell
end run
Since you mentioned you're new to AppleScript does it have to run in the Terminal.app or is a shell enough? AppleScript has the command do shell script
which opens a shell, execute the text and return the stdout back to you.
on run argv
do shell shell script "/path/to/myscanprogram " & quoted form of (item 1 of argv) & " 2>&1"
end run
Last but not least. If you don't want the output of the scan program and don't want AppleScript to wait until it's finished you can use
on run argv
do script "/path/to/myscanprogram " & quoted form of (item 1 of argv) & " &>/dev/null &"
end run
1
Yes, you're right. I had a strange fear of quoting the arguments twice, because you have to quote your input if it contains spaces. Otherwise the argument could be parsed as two arguments instead of one. BUT: I tested it and the savest way is the use ofquoted form
indeed and it works if the shell argument is already quoted, too! ;-) thumbsup
– ShooTerKo
Mar 27 '15 at 10:13
add a comment |
Why doesn't anyone mention quoted form of
? When you want to send arbitrary data as an argument to an application you should use quoted form of. When quotes, spaces and other special characters are in the given path the command will break down in de previous examples.
on run argv
tell application "Terminal"
do script "./myscanprogram " & quoted form of (item 1 of argv) & " 2>&1"
end tell
end run
Since you mentioned you're new to AppleScript does it have to run in the Terminal.app or is a shell enough? AppleScript has the command do shell script
which opens a shell, execute the text and return the stdout back to you.
on run argv
do shell shell script "/path/to/myscanprogram " & quoted form of (item 1 of argv) & " 2>&1"
end run
Last but not least. If you don't want the output of the scan program and don't want AppleScript to wait until it's finished you can use
on run argv
do script "/path/to/myscanprogram " & quoted form of (item 1 of argv) & " &>/dev/null &"
end run
1
Yes, you're right. I had a strange fear of quoting the arguments twice, because you have to quote your input if it contains spaces. Otherwise the argument could be parsed as two arguments instead of one. BUT: I tested it and the savest way is the use ofquoted form
indeed and it works if the shell argument is already quoted, too! ;-) thumbsup
– ShooTerKo
Mar 27 '15 at 10:13
add a comment |
Why doesn't anyone mention quoted form of
? When you want to send arbitrary data as an argument to an application you should use quoted form of. When quotes, spaces and other special characters are in the given path the command will break down in de previous examples.
on run argv
tell application "Terminal"
do script "./myscanprogram " & quoted form of (item 1 of argv) & " 2>&1"
end tell
end run
Since you mentioned you're new to AppleScript does it have to run in the Terminal.app or is a shell enough? AppleScript has the command do shell script
which opens a shell, execute the text and return the stdout back to you.
on run argv
do shell shell script "/path/to/myscanprogram " & quoted form of (item 1 of argv) & " 2>&1"
end run
Last but not least. If you don't want the output of the scan program and don't want AppleScript to wait until it's finished you can use
on run argv
do script "/path/to/myscanprogram " & quoted form of (item 1 of argv) & " &>/dev/null &"
end run
Why doesn't anyone mention quoted form of
? When you want to send arbitrary data as an argument to an application you should use quoted form of. When quotes, spaces and other special characters are in the given path the command will break down in de previous examples.
on run argv
tell application "Terminal"
do script "./myscanprogram " & quoted form of (item 1 of argv) & " 2>&1"
end tell
end run
Since you mentioned you're new to AppleScript does it have to run in the Terminal.app or is a shell enough? AppleScript has the command do shell script
which opens a shell, execute the text and return the stdout back to you.
on run argv
do shell shell script "/path/to/myscanprogram " & quoted form of (item 1 of argv) & " 2>&1"
end run
Last but not least. If you don't want the output of the scan program and don't want AppleScript to wait until it's finished you can use
on run argv
do script "/path/to/myscanprogram " & quoted form of (item 1 of argv) & " &>/dev/null &"
end run
answered Mar 25 '15 at 20:52
dj bazzie wazziedj bazzie wazzie
3,0421422
3,0421422
1
Yes, you're right. I had a strange fear of quoting the arguments twice, because you have to quote your input if it contains spaces. Otherwise the argument could be parsed as two arguments instead of one. BUT: I tested it and the savest way is the use ofquoted form
indeed and it works if the shell argument is already quoted, too! ;-) thumbsup
– ShooTerKo
Mar 27 '15 at 10:13
add a comment |
1
Yes, you're right. I had a strange fear of quoting the arguments twice, because you have to quote your input if it contains spaces. Otherwise the argument could be parsed as two arguments instead of one. BUT: I tested it and the savest way is the use ofquoted form
indeed and it works if the shell argument is already quoted, too! ;-) thumbsup
– ShooTerKo
Mar 27 '15 at 10:13
1
1
Yes, you're right. I had a strange fear of quoting the arguments twice, because you have to quote your input if it contains spaces. Otherwise the argument could be parsed as two arguments instead of one. BUT: I tested it and the savest way is the use of
quoted form
indeed and it works if the shell argument is already quoted, too! ;-) thumbsup– ShooTerKo
Mar 27 '15 at 10:13
Yes, you're right. I had a strange fear of quoting the arguments twice, because you have to quote your input if it contains spaces. Otherwise the argument could be parsed as two arguments instead of one. BUT: I tested it and the savest way is the use of
quoted form
indeed and it works if the shell argument is already quoted, too! ;-) thumbsup– ShooTerKo
Mar 27 '15 at 10:13
add a comment |
Wondering why you're using your Terminal to address an AppleScript that uses the Terminal again, but maybe I just don't know your circumstances...
Applescript:
on run argv
tell application "Terminal"
do script "./myscanprogram " & (item 1 of argv) & " 2>&1"
end tell
end run
Call from osascript inside your Terminal:
osascript pathToYourScript.scpt myargument
add a comment |
Wondering why you're using your Terminal to address an AppleScript that uses the Terminal again, but maybe I just don't know your circumstances...
Applescript:
on run argv
tell application "Terminal"
do script "./myscanprogram " & (item 1 of argv) & " 2>&1"
end tell
end run
Call from osascript inside your Terminal:
osascript pathToYourScript.scpt myargument
add a comment |
Wondering why you're using your Terminal to address an AppleScript that uses the Terminal again, but maybe I just don't know your circumstances...
Applescript:
on run argv
tell application "Terminal"
do script "./myscanprogram " & (item 1 of argv) & " 2>&1"
end tell
end run
Call from osascript inside your Terminal:
osascript pathToYourScript.scpt myargument
Wondering why you're using your Terminal to address an AppleScript that uses the Terminal again, but maybe I just don't know your circumstances...
Applescript:
on run argv
tell application "Terminal"
do script "./myscanprogram " & (item 1 of argv) & " 2>&1"
end tell
end run
Call from osascript inside your Terminal:
osascript pathToYourScript.scpt myargument
edited Nov 12 '18 at 20:08
Utku
849827
849827
answered Mar 25 '15 at 15:45
ShooTerKoShooTerKo
1,7441815
1,7441815
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f29258142%2fhow-can-i-open-applescript-app-with-arguments%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown