If then statement using applescript in mac terminal?
5,136
In bash (command line):
if [ "$foo" = "1" ] ; then
foo=18
fi
in AppleScript:
if foo equals 1 then
set foo to 18
end if
Responding to the comments:
set foo to 5
tell application "System Events"
tell application "Firefox" to activate
keystroke (foo as text) using command down
end tell
You can probably append this to my answer to your previous question as-is, minus the set foo
line.
Author by
User19
Updated on September 18, 2022Comments
-
User19 over 1 year
What would be the code for:
"If $foo is one, then $foo should now equal 18" ?
Thanks
-
HikeMike about 13 yearsDidn't you want all values converted to their key codes? Or just
1
? -
HikeMike about 13 yearsTo others, FYI: This is a question following this other topic. @JShoe: I think you need to explain more fully what you want to do here. AppleScript and Terminal/bash scripting are two completely separate things and your questions don't make a whole lot of sense to me, to be honest.
-
User19 about 13 yearsIs there a way to convert them to their key codes? I'm only working with 1-10 in the program I'm making.
-
HikeMike about 13 years
10
is not a key. Do you mean0
? -
User19 about 13 yearsWell yeah, but the input of my program is 1-10. It's going to open tabs in firefox. Tab 10 = command + 0.
-
HikeMike about 13 yearsThen I suggest
keystroke foo using command down
. That's why I keep asking what it is you want to do. -
User19 about 13 yearsBut keystroke foo when foo = 1 will give me s. First I have to convert it to the correct key code, right?
-
-
HikeMike about 13 years@JShoe It marks the end of the block of code only executed if the condition is true
-
User19 about 13 yearsDo I need "foo as text"? Wouldnt $foo work?
-
HikeMike about 13 years
$foo
is bash syntax. This example is for when you add it directly to the end of the previous script. Or do you want to pipe the output of one AppleScript into another using bash, when you can just append one to the other? Replace anyreturn
withset foo to
in the dialog script and it should work.