Applescript to turn on Airport

Hi,

I’m on wireless and I was wondering if I could make a script to use when I log in to set Airport to get it’s signal. When I log in it’s already on I just need to set it to it’s signal. Can anyone help me please?

Is this what you need?

http://bbs.applescript.net/viewtopic.php?id=5467

No, I need the script to (after I log in) automatically set it to “Airport”. Instead of manually setting it. I want to have apps in my start up items to happen but they require an internet connection so if this script sets it up before the app launches it’ll be fine.

Sorry, I misunderstood. Airport turns on automatically for me; I don’t remember how I set it up originally and I haven’t thought of it since.

How about this?


--Save it as an application and add it to you login items.

tell application "Internet Connect"
	activate
	tell application "System Events"
		
		tell window 1 of process "Internet Connect"
			tell button "Airport" of tool bar 1
				click
			end tell
			
			tell button "Turn AirPort On"
				click
			end tell
			
		end tell
	end tell
end tell

delay 3
tell application "Internet Connect" to quit

--You could activate the other programs next instead of having them in login items separately:

--tell application "Application" name to activate


That script works when Airport is off. When I log in it’s already on. I want it select the Network “Airport”. I wasn’t clear in the previous posts sorry. It’d also be nice if it did it without bringing up the internet connect window.

Hi Harry.

Oops, you said that in your first post.

I just read your posts again, and I’m not sure I understand yet - sorry. When you log in, Airport is on but…

Are you connected by Ethernet instead? Are you connected to the wrong wireless network?

Do you mean select Airport instead of Built-in Ethernet, etc.? Moving Airport to the top of the list in System Preferences>Network>Show:Network Port Configurations will work, unless you have a reason not to do that.

Or do you want to select a wireless network named “Airport” from among your available wireless networks? System preferences is a possible solution again

If what you want done requires GUI scripting (don’t know that yet) the window will have to open.

That’s the one lol.

Okay, that I can help with. Hang on a bit…

Only had about 10 minutes, so I’ll post the unfinished script. I’ll get back to it after dinner.
It’s GUI for now, didn’t have time to figure out if it could be done without it.

By the way, is there a reason Airport doesn’t select your “Airport” network by default?


tell application "Internet Connect"
	activate
	tell application "System Events"
		
		tell window 1 of process "Internet Connect"
			tell pop up button 1
				click
				end tell
			end tell
		end tell
		
	end tell
end tell

tell application "Internet Connect" to quit

How’s this?

tell application "Internet Connect"
	activate
	tell application "System Events"
		tell window 1 of process "Internet Connect"
			click button 2 of tool bar 1
			tell pop up button 1
				click
				click menu item "Airport" of menu 1
			end tell
		end tell
	end tell
       quit
end tell

EDITED: to add quit

You might also try the interesting scripting addition XNetwork.osax, see scripting addition part of this board or OSAXen.com.

Thanks alot cap! Works like a charm. I tried to do the exact thing, but got it mixed up with the wording of the popup button and such.

Glad to help. I had trouble with it, too, even though I’d seen it done somewhere before. I need to organize my references better.

I don’t know if Eelco’s suggestion would help make the proscess invisible. I’m sticking with plain vanilla Applescript for now.

j

Hey guys this is my first post and this thread was right up my alley in my Google search so I registered right away. My background is as a veteran Mac user (since 1990) and yet have never done much with AppleScript.

Anyway, is there a way to modify this script to turn Airport on/off from the same script? I know an if statement or something would probably do it, but I was unable to get it to work. I would prefer to have a toggle script rather than two different scripts for on and off.

Thanks guys, I hope to learn about Applescript language quickly, as I am a moderate user of other languages.

Do you want a script that toggles Airport off then back on? (as in this thread http://bbs.applescript.net/viewtopic.php?id=17337)

Or you want a script that first offers a choice between turning Airport on or off depending on it’s current state, then offers a choice to select a network or quit the script?

j

I do not want a script like in the link you sent me.

Yes, I want a script that will turn off airport if it is on, and turn it on if it is off. I don’t want it to task me, I just want it to do it. Isn’t there a way that an if statement could be used to do this?

I hope that makes sense. Again I am just beginning with AppleScript after I realized that Automator is just not powerful enough.

I just quickly changed the GUI script for now - the kids need Dad to make lunch.

Edit - I was hoping to find a way to do this without GUI, but I couldn’t.


tell application "Internet Connect"
	activate
	tell application "System Events"
		
		tell window 1 of process "Internet Connect"
			tell button "Airport" of tool bar 1
				click
				
			end tell
			
			if exists button "Turn AirPort On" then
				tell button "Turn Airport On"
					click
				end tell
				
			else
				tell button "Turn Airport Off"
					click
				end tell
			end if
			
		end tell
		
	end tell
	quit
end tell

Thanks CapJ, that is exactly what I wanted. I look forward to learning from you and others in the future.
I want to do this for Bluetooth as well, and I will give it a shot using this script as a reference (or skeleton).

This is what I got for activating Bluetooth via GUI commands in System Preferences. It doesn’t activate, and it errors out on the Else for turning bluetooth off. I think I’m really close. But just can’t get it. Little Help?

tell application "System Preferences"
	activate
	set current pane to pane "com.apple.preferences.Bluetooth"
	
	tell application "System Events" to tell window "Bluetooth" of process "System Preferences"
		click radio button "Settings" of tab group 1
		
		if exists button "Turn Bluetooth On" then
			tell button "Turn Bluetooth On"
				click
			end tell
			
		else
			
			tell button "Turn Bluetooth Off"
				click
			end tell
		end if
		
	end tell
end tell
quit application "System Preferences"

I haven’t figured this out yet, but this event log:

is the result of this script:


tell application "System Preferences"
	activate
	set current pane to pane "com.apple.preferences.Bluetooth"
	
	tell application "System Events" to tell window "Bluetooth" of process "System Preferences"
		click radio button "Settings" of tab group 1
		
		if exists button "Turn Bluetooth On" then
			tell button "Turn Bluetooth On"
				click
			end tell
		end if
		
	end tell
end tell
--quit application "System Preferences"

Of course, I’m looking at the button that supposedly doesn’t exist. I tried to repeat through the groups to check for the button, but that didn’t work. I’ll keep trying. Maybe somebody else will have the solution.

j