Super simple Applescript - but how to write it?

Discussion in 'Mac Programming' started by Jigglelicious, Oct 7, 2004.

  1. macrumors 6502

    Jigglelicious

    Joined:
    Apr 25, 2004
    Location:
    NYC
    #1
    With the discontinuation of the original Airport card, i've been looking for a decent replacement. I think i've found one with a Belkin USB wireless receiver. The problem is, it doesn't automatically connect to the network when the computer is restarted - you have to run the software manually and start it, which is annoying and I don't want my parents to have to do.

    So I realized i could probably do it with Applescript and have it run automatically on start up. The problem is, I don't know any Applescript. As far as I can tell, the steps required are very simple.

    1.) start the Belkin driver utility (this much I can do)
    2.) hit return
    3.) wait 5 seconds
    4.) quit app

    Thats it. I've tried writing this but i keep getting applescript errors. Can anyone help with writing this? Thanks a lot :)
     
  2. macrumors member

    Joined:
    Oct 7, 2004
    #2
    i dont have or know of this program, so you'll have to be patient with me.

    what do you mean "hit return"?

    pausing for five seconds:
    Code:
    do shell script "sleep 5"
    quiting the utility is also pretty simple, but it also depends on if this program is scriptable. how did you get it to launch (exact code would be appreciated)
     
  3. macrumors member

    Joined:
    Oct 7, 2004
    #3
    you should try asking these questions at http://www.macscripter.net

    they have an active applescripter community and a forum system as well.
     
  4. Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #4
    I'm not sure if you can emulate key presses in AppleScript but you could:

    do shell script "echo '\n'"


    To wait 5 seconds in AppleScript:

    delay 5 should work
     
  5. macrumors G3

    iMeowbot

    Joined:
    Aug 30, 2003
    #5
    Recent editions of OS X can use a cool little AppleScript helper program called System Events that will work even on programs that haven't implemented scripting. This comes with Panther, and a Jaguar version can be downloaded from Apple (developer tools).

    Here is a little example showing how to transmit key presses.

    Code:
    set CR to ASCII character of 13
    tell application "System Events"
    	tell application "TextEdit" to activate
    	keystroke "n" using command down -- new file
    	keystroke "meow," & CR & "meow," & CR & "woof!" & CR -- add some text
    	keystroke "s" using command down -- save
    	keystroke "mymeowfile" & CR
    	keystroke "q" using command down -- quit
    end tell
    
     
  6. thread starter macrumors 6502

    Jigglelicious

    Joined:
    Apr 25, 2004
    Location:
    NYC
    #6
    Well, I tried to run this Applescript (which LOOKS like it should work), but I get an error.

    Code:
    tell application "Belkin Wireless LAN C#23FD9"
    	tell application "Belkin Wireless LAN C#23FD9" to activate
    	keystroke return
    	delay 5
    	quit
    end tell
    gives me the following error:
    Belkin Wireless LAN Configuration got an error: Can't get keystroke "
    ".

    Any idea what i'm doing wrong?
     
  7. macrumors G3

    iMeowbot

    Joined:
    Aug 30, 2003
    #7
    Yeah, return doesn't mean that in AppleScript =)

    You want something closer to this:

    Code:
    tell application "System Events"
        tell application "Belkin Wireless LAN C#23FD9" to activate
        keystroke (ASCII character of 13)
        delay 5
        keystroke "q" using command down
    end tell
    
    [explaining more: the keystroke thingy comes from the System Events program, bare AppleScript can't do that.]
     
  8. thread starter macrumors 6502

    Jigglelicious

    Joined:
    Apr 25, 2004
    Location:
    NYC
    #8

    Wow thanks! That worked out perfectly. Now my parents don't have to worry about running the damned utility to start up the wireless connection every time they turn the computer on.

    Oh yeah, the reason i thought 'return' would hit return on the keyboard was because I was looking through some of the sample Applescripts and i saw it used quite often, so i just assumed :)
     
  9. macrumors G3

    iMeowbot

    Joined:
    Aug 30, 2003
    #9
    Yeah, AppleScript messes up everybody! It's a horrible language, and so is its documentation. But it does work :D
     
  10. macrumors newbie

    Joined:
    Sep 22, 2007
    #10
    when I have the script
    set CR to ASCII character of 13

    tell application "System Events"
    tell application "TextEdit" to activate
    keystroke "n" using command down -- new file
    keystroke "meow," & CR & "meow," & CR & "woof!" & CR -- add some text
    keystroke "s" using command down -- save
    keystroke "mymeowfiles" & CR
    keystroke "q" using command down -- quit
    end tell

    it won't work but when i take the s of of mymeowfiles to become mymeowfile again it works what is going on shouldn't you be able to have any name??
     

Share This Page