PDA

View Full Version : Super simple Applescript - but how to write it?




Jigglelicious
Oct 7, 2004, 09:19 PM
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
Oct 7, 2004, 10:29 PM
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:
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)

widgetman
Oct 7, 2004, 10:32 PM
you should try asking these questions at http://www.macscripter.net

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

bousozoku
Oct 7, 2004, 11:49 PM
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
Oct 8, 2004, 03:53 AM
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.


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
Oct 8, 2004, 07:21 AM
Well, I tried to run this Applescript (which LOOKS like it should work), but I get an error.

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
Oct 8, 2004, 08:09 AM
Yeah, return doesn't mean that in AppleScript =)

You want something closer to this:


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
Oct 8, 2004, 10:54 AM
Yeah, return doesn't mean that in AppleScript =)

You want something closer to this:


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
Oct 8, 2004, 03:15 PM
Yeah, AppleScript messes up everybody! It's a horrible language, and so is its documentation. But it does work :D

gumby777
Oct 17, 2007, 06:20 PM
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??