Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

What would be the code for:

"If $foo is one, then $foo should now equal 18" ?

Thanks

share|improve this question
    
Didn't you want all values converted to their key codes? Or just 1? –  Daniel Beck Apr 9 '11 at 16:48
    
To 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. –  Daniel Beck Apr 9 '11 at 16:49
    
Is there a way to convert them to their key codes? I'm only working with 1-10 in the program I'm making. –  JShoe Apr 9 '11 at 16:54
    
10 is not a key. Do you mean 0? –  Daniel Beck Apr 9 '11 at 16:55
    
Well yeah, but the input of my program is 1-10. It's going to open tabs in firefox. Tab 10 = command + 0. –  JShoe Apr 9 '11 at 16:57
show 2 more comments

1 Answer

up vote 2 down vote accepted

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.

share|improve this answer
    
Cool thanks. Also, what's "fi"? –  JShoe Apr 9 '11 at 16:54
    
@JShoe It marks the end of the block of code only executed if the condition is true –  Daniel Beck Apr 9 '11 at 16:56
    
Do I need "foo as text"? Wouldnt $foo work? –  JShoe Apr 9 '11 at 17:08
    
$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 any return with set foo to in the dialog script and it should work. –  Daniel Beck Apr 9 '11 at 17:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.