Can somebody make me a script?

Discussion in 'Mac Programming' started by Simo1122, Jan 29, 2009.

  1. macrumors member

    Simo1122

    Joined:
    Jan 28, 2009
    #1
    I have no idea how to make scripts but I would love if somebody could make one for me

    I want it to do this (I have been doing it via terminal)

    1. Turn Airport ON

    2. Disconnect it from any network.

    3. sudo ifconfig en1 lladdr (mac address here)

    4. Connect it to (my wireless network)

    I want it to be able to be changed script editor so I can enter my MAC address and the network name I want it to join. If it's possible.

    The network reconnect is not very important but it would be good..
     
  2. macrumors P6

    twoodcc

    Joined:
    Feb 3, 2005
    Location:
    Right side of wrong
    #2
    so you are doing all of this in the terminal already?
     
  3. thread starter macrumors member

    Simo1122

    Joined:
    Jan 28, 2009
    #3
    All i don't know how to do is turn airport ON and disconnect from networks..
     
  4. macrumors 68020

    Tex-Twil

    Joined:
    May 28, 2008
    Location:
    Europe
    #4
    Hi again ;)
    to disconnect airport from the network without turning it off:

    Code:
    /System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -z
    
    
    See help of this command for other usage:

    Code:
    /System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -help
    /System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport AirPort v.524.1 (524.1.0)
    Supported arguments:
     -z        --disassociate       Disassociate from any network
     -i[<arg>] --ibss=[<arg>]       Create IBSS
     -x        --xml                Print info as XML
     -s[<arg>] --scan=[<arg>]       Perform a wireless broadcast scan.
    				   Will perform a directed scan if the optional <arg> is provided
     -r<arg>   --repeats=<arg>      Repeat the command the specified number of times
     -A[<arg>] --associate=[<arg>]  Associate to network.
    				   Will prompt for network name if arg is not specified
    				   and if necessary, for a password if the network is using WEP or WPA.
    				   The following additional arguments may be specified with this command:
                                      --bssid=<arg>     Specify BSSID to associate with
                                      --password=<arg>  Specify a WEP key or WPA password
     -I        --getinfo            Print current wireless status, e.g. signal info, BSSID, port type etc.
     -P<arg>   --psk=<arg>          Create PSK from specified pass phrase and SSID.
    				   The following additional arguments must be specified with this command:
                                      --ssid=<arg>      Specify SSID when creating a PSK
     -c[<arg>] --channel=[<arg>]    Set arbitrary channel on the card
     -h        --help               Show this help
    
    
     
  5. thread starter macrumors member

    Simo1122

    Joined:
    Jan 28, 2009
    #5
    Hey Tex,
    Thanks for the help. So far I have nearly got it except how do I make it enter a password under LEAP? Not WEP or the others.

    If I have the wireless network saved in system prefs, if I tell it to join it should it do it automatically? (I can't test it until monday)
     
  6. macrumors 68020

    Tex-Twil

    Joined:
    May 28, 2008
    Location:
    Europe
    #6
    I dont know how to turn ON the airport via command line but the script could look like this. Note that the password of the wlan is stored in the script so make sure that it is readable only by root.

    Code:
    #!/bin/bash 
    
    AIRPORT_BIN="/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport"
    
    # name and password (!!) for your wlan
    MY_ESSID="my_wlan"
    MY_PASSWORD="my_password"
    
    
    IF_BIN="/sbin/ifconfig"
    IFACE="en1"
    
    NEW_MAC="00:23:12:xx:xx:xx"
    
    # disconnect
    $AIRPORT_BIN -z
    
    # wait 10 seconds !
    sleep 10
    
    # change the mac
    $IF_BIN $IFACE lladdr $NEW_MAC
    
    
    #reconnect
    $AIRPORT_BIN --associate=$MY_ESSID --password=$MY_PASSWORD
    
    We are not sure how to change the mac of the airport correctly (see your previous post). It looks like the mac is NOT changed if it ifconfig is executed just after the disconnect command and that"s why I put a sleep of 10 seconds.

    This is just a very quick script that could/should be enhanced.

    Cheers,
    Tex
     
  7. macrumors 68020

    Tex-Twil

    Joined:
    May 28, 2008
    Location:
    Europe
    #7
    I don't think that it will use the password automatically. The LEAP authentication might be a problem since the command line tool doesn't seem to have a parameter for such a password. Just try and see.
     
  8. thread starter macrumors member

    Simo1122

    Joined:
    Jan 28, 2009
    #8
    Hey,

    How do I enter that sleep thing in this command line

    [​IMG]

    Because thats the problem for it not working.
     
  9. Administrator emeritus

    xUKHCx

    Joined:
    Jan 15, 2006
    Location:
    The Kop
    #9
    Seeing as you are in apple script may as well use the delay command between the other commands.

    e.g.

    delay 10
     
  10. macrumors 68020

    Tex-Twil

    Joined:
    May 28, 2008
    Location:
    Europe
    #10
    Why do you use an Apple Script if you then use shell script. You can directly use a shell script as I posted before.

    T
     
  11. thread starter macrumors member

    Simo1122

    Joined:
    Jan 28, 2009
    #11
    I'm so confused. I'm only using applescript because thats the only thing i have the slightest grasp on..
     
  12. thread starter macrumors member

    Simo1122

    Joined:
    Jan 28, 2009
    #12
    Ok now I'm less confused.

    The thing you posted above, can I put that in script editor?
     
  13. Administrator emeritus

    xUKHCx

    Joined:
    Jan 15, 2006
    Location:
    The Kop
    #13
    Yeah straight in

    e.g.

    do shell script "......
    delay 10
    do shell script ".....
     
  14. macrumors 68020

    Tex-Twil

    Joined:
    May 28, 2008
    Location:
    Europe
    #14
    No. The bash script is just a sequence of bash (~=Terminal) commands that you put in a text file and then execute the file.

    So copy and paste the script I posted in a text file, save the file somewhere e.g. myscript. Then in a terminal, make it executable:
    Code:
    chmod +x myscript
    
    and run :

    Code:
    ./myscript
    
    ;)
     
  15. macrumors 68020

    Tex-Twil

    Joined:
    May 28, 2008
    Location:
    Europe
    #15
    I think the "you" refered to me :)
     
  16. thread starter macrumors member

    Simo1122

    Joined:
    Jan 28, 2009
    #16
    No such file or directory
    :(

    Do i have to save it somewhere specific or add to your terminal line?
     
  17. macrumors 68020

    Tex-Twil

    Joined:
    May 28, 2008
    Location:
    Europe
    #17
    Well zou have to be in the same directory where your "myscript" file is. If you create it on your Desktop, you first have to "cd" to your Desktop:

    Code:
    cd Desktop
    chmod +x myscript
    ./myscript
    
    or


    Code:
    chmod +x /Users/yourlogin/Desktop/myscript
    /Users/yourlogin/Desktop/myscript
    
    T.
     

Share This Page