Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Jigglelicious

macrumors 6502
Original poster
Apr 25, 2004
421
0
NYC
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 :)
 

widgetman

macrumors member
Oct 7, 2004
39
0
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)
 

bousozoku

Moderator emeritus
Jun 25, 2002
16,120
2,397
Lard
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
 

iMeowbot

macrumors G3
Aug 30, 2003
8,634
0
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
 

Jigglelicious

macrumors 6502
Original poster
Apr 25, 2004
421
0
NYC
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?
 

iMeowbot

macrumors G3
Aug 30, 2003
8,634
0
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.]
 

Jigglelicious

macrumors 6502
Original poster
Apr 25, 2004
421
0
NYC
iMeowbot said:
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.]


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 :)
 

iMeowbot

macrumors G3
Aug 30, 2003
8,634
0
Yeah, AppleScript messes up everybody! It's a horrible language, and so is its documentation. But it does work :D
 

gumby777

macrumors newbie
Sep 22, 2007
8
0
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??
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.