Mixing in AppleScript

Discussion in 'Mac Programming' started by iDevCplusplus, Feb 23, 2010.

  1. iDevCplusplus macrumors newbie

    Jan 30, 2010
    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?
    -Blake Ehrenbeck
  2. kainjow Moderator emeritus


    Jun 15, 2000
    What language/framework are you working with?
  3. iDevCplusplus thread starter macrumors newbie

    Jan 30, 2010
    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
  4. fredthefool macrumors newbie

    Jun 4, 2008
    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:

    property SSID : "YOUR_WLAN_SSID"
    property PWD : "YOUR_WLAN_PASSWORD"
    on run
    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.

Share This Page