Skip to content

Instantly share code, notes, and snippets.

@sqlwwx
Forked from Jeff2Ma/Dorm-network.scpt
Created May 18, 2016 23:07
Show Gist options
  • Save sqlwwx/04f1d67c2716c9f93a7473f9be0e341c to your computer and use it in GitHub Desktop.
Save sqlwwx/04f1d67c2716c9f93a7473f9be0e341c to your computer and use it in GitHub Desktop.

Revisions

  1. @Jeff2Ma Jeff2Ma revised this gist Jul 13, 2015. No changes.
  2. @Jeff2Ma Jeff2Ma revised this gist Jul 13, 2015. 2 changed files with 63 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions Office-network.scpt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    tell application “Shad**socksX"
    quit
    end tell
    tell application "System Events"
    tell network preferences
    do shell script "scselect 'Office'"
    do shell script "sudo networksetup -setairportpower AirPort on" user name “用户名" password "密码" with administrator privileges
    do shell script "/Users/name/documents/setpac.sh" user name “用户名" password "密码" with administrator privileges
    end tell
    end tell
    53 changes: 53 additions & 0 deletions setpac.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    #!/bin/sh
    ####################################################################################################
    #
    # More information: https://macmule.com/2014/12/07/how-to-change-the-automatic-proxy-configuration-url-in-system-preferences-via-a-script/
    #
    # GitRepo: https://github.com/macmule/setAutomaticProxyConfigurationURL
    #
    # License: http://macmule.com/license/
    #
    ####################################################################################################

    # HARDCODED VALUES ARE SET HERE
    autoProxyURL=“PAC 文件路径"
    # CHECK TO SEE IF A VALUE WAS PASSED FOR $4, AND IF SO, ASSIGN IT
    if [ "$4" != "" ] && [ "$autoProxyURL" == "" ]; then
    autoProxyURL=$4
    fi
    # Detects all network hardware & creates services for all installed network hardware
    /usr/sbin/networksetup -detectnewhardware
    IFS=$'\n'
    #Loops through the list of network services
    for i in $(networksetup -listallnetworkservices | tail +2 );
    do
    # Get a list of all services beginning 'Ether' 'Air' or 'VPN' or 'Wi-Fi'
    # If your service names are different to the below, you'll need to change the criteria
    if [[ "$i" =~ 'Ether' ]] || [[ "$i" =~ 'Air' ]] || [[ "$i" =~ 'VPN' ]] || [[ "$i" =~ 'Wi-Fi' ]] ; then
    autoProxyURLLocal=`/usr/sbin/networksetup -getautoproxyurl "$i" | head -1 | cut -c 6-`
    # Echo's the name of any matching services & the autoproxyURL's set
    echo "$i Proxy set to $autoProxyURLLocal"
    # If the value returned of $autoProxyURLLocal does not match the value of $autoProxyURL for the interface $i, change it.
    if [[ $autoProxyURLLocal != $autoProxyURL ]]; then
    /usr/sbin/networksetup -setautoproxyurl $i $autoProxyURL
    echo "Set auto proxy for $i to $autoProxyURL"
    fi
    fi
    # Enable auto proxy once set
    /usr/sbin/networksetup -setautoproxystate "$i" on
    echo "Turned on auto proxy for $i"
    done
    unset IFS
    # Echo that we're done
    echo "Auto proxy present, correct & enabled for all targeted interfaces"
  3. @Jeff2Ma Jeff2Ma created this gist Jul 13, 2015.
    7 changes: 7 additions & 0 deletions Dorm-network.scpt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    tell application "System Events"
    tell network preferences
    do shell script "scselect 'Dorm'"
    do shell script "sudo networksetup -setairportpower AirPort on" user name "用户名" password "密码" with administrator privileges
    do shell script "open /Applications/Shad**socksX.app" user name “用户名" password "密码" with administrator privileges
    end tell
    end tell