Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Oct 7, 2004, 09:19 PM   #1
Jigglelicious
macrumors 6502
 
Join Date: Apr 2004
Location: NYC
Super simple Applescript - but how to write it?

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
__________________
Powermac G4 Cube: 600MHz G4, 60GB Seagate Barracuda V, 1.5GB RAM, Pioneer DVR-K05 8x DVD-RW/DL, ATI Radeon 9200 128mb, SGI 1600SW 17" Widescreen
Jigglelicious is offline   0 Reply With Quote
Old Oct 7, 2004, 10:29 PM   #2
widgetman
macrumors member
 
Join Date: Oct 2004
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)
widgetman is offline   0 Reply With Quote
Old Oct 7, 2004, 10:32 PM   #3
widgetman
macrumors member
 
Join Date: Oct 2004
you should try asking these questions at http://www.macscripter.net

they have an active applescripter community and a forum system as well.
widgetman is offline   0 Reply With Quote
Old Oct 7, 2004, 11:49 PM   #4
bousozoku
Retired (Moderator emeritus)
 
Join Date: Jun 2002
Location: Gone but not forgotten.
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
bousozoku is offline   0 Reply With Quote
Old Oct 8, 2004, 03:53 AM   #5
iMeowbot
macrumors 601
 
iMeowbot's Avatar
 
Join Date: Aug 2003
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
iMeowbot is offline   0 Reply With Quote
Old Oct 8, 2004, 07:21 AM   #6
Jigglelicious
Thread Starter
macrumors 6502
 
Join Date: Apr 2004
Location: 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?
__________________
Powermac G4 Cube: 600MHz G4, 60GB Seagate Barracuda V, 1.5GB RAM, Pioneer DVR-K05 8x DVD-RW/DL, ATI Radeon 9200 128mb, SGI 1600SW 17" Widescreen
Jigglelicious is offline   0 Reply With Quote
Old Oct 8, 2004, 08:09 AM   #7
iMeowbot
macrumors 601
 
iMeowbot's Avatar
 
Join Date: Aug 2003
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.]

Last edited by iMeowbot; Oct 8, 2004 at 08:14 AM.
iMeowbot is offline   0 Reply With Quote
Old Oct 8, 2004, 10:54 AM   #8
Jigglelicious
Thread Starter
macrumors 6502
 
Join Date: Apr 2004
Location: NYC
Quote:
Originally Posted by iMeowbot
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
__________________
Powermac G4 Cube: 600MHz G4, 60GB Seagate Barracuda V, 1.5GB RAM, Pioneer DVR-K05 8x DVD-RW/DL, ATI Radeon 9200 128mb, SGI 1600SW 17" Widescreen
Jigglelicious is offline   0 Reply With Quote
Old Oct 8, 2004, 03:15 PM   #9
iMeowbot
macrumors 601
 
iMeowbot's Avatar
 
Join Date: Aug 2003
Yeah, AppleScript messes up everybody! It's a horrible language, and so is its documentation. But it does work
iMeowbot is offline   0 Reply With Quote
Old Oct 17, 2007, 06:20 PM   #10
gumby777
macrumors newbie
 
Join Date: Sep 2007
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??
gumby777 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
I know where it's "@" - but how to type it? c-Row Windows, Linux & others on the Mac 21 Jul 30, 2012 01:22 PM
Ok, I screwed up and paid full price - But how to log in? Piggie iCloud and Apple services 4 Feb 7, 2011 04:50 PM
FREE Normal Ringtone BUT How to get it to repeat? covertsurfer iPhone 4 Jul 9, 2009 08:36 AM
iPhone app: playing sound will 'pause' ipod, but how to start it again? MaFt iPhone/iPad Programming 0 Feb 12, 2009 02:07 PM


All times are GMT -5. The time now is 12:51 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC