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

iDevCplusplus

macrumors newbie
Original poster
Jan 30, 2010
13
0
Hey Everyone,

I am trying to write an application where a user clicks a button and then an applescript script will turn on Wifi and do various system activities. How could I go about doing this?
Thanks
-Blake Ehrenbeck
 
Not Sure

I am kind of confused about the framework. I want to write a Cocoa App in Objective-C that triggers an applescript method that does a system task. Could you post some tutorials or some guides on how I could go about doing this. I want this app to turn on the users WiFi when a button is clicked. Do I even need AppleScript to do this. I am in desperate need of help, please respond.

-Blake Eherenbeck
 
Probably you need nothing more than just AppleScript, because its ability to glue together various system commands is outstanding ...

I assume you are familiar with AppleScript, so the "system call" you're looking for is in as subdirectory of /System/Library and is called "airport". Running this command, you need Administrator privileges, so running the script will prompt for such a password.

I don't know what other "various system activities" your script will be designed to do, but this should give you a start:


Code:
property SSID : "YOUR_WLAN_SSID"
property PWD : "YOUR_WLAN_PASSWORD"

on run
	perform_actions()
end run

on perform_actions()
	set wireless_down to "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -z"
	
	set wireless_up to "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport --associate --ssid=" & SSID & " --password=" & PWD
	
	do shell script wireless_down with administrator privileges
	
	do shell script wireless_up with administrator privileges
	
end perform_actions

The first call, "wireless_down" will disassociate from any actual wireless network, the second will associate with the wireless network according to the properties (replace them with those of your network).

The computer's Airport card has to be activated to assure this script's functionality.


In Scripteditor, save it as "program bundle" for this will give you a "clickable" app with an icon you'll be able to put on your desktop or the dock.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.