8 Replies Latest reply: Apr 28, 2012 10:38 AM by Pierre L.
personal_username Level 1 Level 1 (0 points)

Hi all,

I'm just wondering if an applescript could be able to create setup and start a private network.

Thanks!


mac mini, Mac OS X (10.6.4)
  • 1. Re: Applescript to start a private network
    MrHoffman Level 6 Level 6 (12,470 points)

    A bash script with the networksetup command probably can do what you need.   See here and here and here for some general examples; that lattermost link is AppleScript calling networksetup to establish a VPN.

     

    It's also possible to set up and manage the network configuration on an OS X client system, using some more advanced tools, such as MCX.    Here's a slightly stale overview of managing OS X client systems.

     

    (And an opinion: Applescript is very good for automating the operations of a GUI app, but it's somewhat clunky for tasks that involve much more than that.  I usually find using something written in a scripting language (bash, Python, etc) to be preferable.)

  • 2. Re: Applescript to start a private network
    Camelot Level 8 Level 8 (45,790 points)

    Kind of light on details there. What is it you're trying to do?

     

    You say 'create'.. does this mean add the configuration data to a machine that's never connected to the VPN before?, or do you just mean establish the secure connection?

     

    What kind of VPN connection? One setup via System Preferences -> Network (e.g. a PPTP or L2TP VPN)? or an SSL-based VPN that's initiated via a browser?

     

    If you're just looking for an easy way to establish a VPN connection, check out the auto-connect options in System Preferences -> Network -> VPN - it can be configured to auto-start the VPN connection whenever you attempt to access a specific hostname or network. This might remove the need for a scripted front-end at all.

  • 3. Re: Applescript to start a private network
    personal_username Level 1 Level 1 (0 points)

    Ok, first of all thank you for your posts.

    What I'm trying to do is actually much simpler thatn what you suggest, i think i wasn't clear enough, sorry.

    I just need to simulate the "create network" in "System Preferences>Network>Network Name".

    Then just press create!

     

    I don't know if i need something like this

     

    tell application "System Preferences"

              reveal pane "Network"

      activate

              tell application "System Events"

    ...

    or just do this in a simpler way without GUI, but both of them would be good for me!

    Thank you!

  • 4. Re: Applescript to start a private network
    MrHoffman Level 6 Level 6 (12,470 points)

    Maybe?

     

    #!/bin/bash

    networksetup -createnetworkservice {networkservicename} {hardwareport}

  • 5. Re: Applescript to start a private network
    personal_username Level 1 Level 1 (0 points)

    not sure what to put on hardwareport...

  • 6. Re: Applescript to start a private network
    Pierre L. Level 4 Level 4 (3,860 points)

    I just need to simulate the "create network" in "System Preferences>Network>Network Name".

    Then just press create!

     

    Then you might want to try this:

     

    tell application "System Preferences"

        activate

        reveal pane id "com.apple.preference.network"

        tell application "System Events" to tell process "System Preferences"

            delay 0.1

            click pop up button "Network Name:" of group 1 of window "Network"

            delay 0.1

            key code 121 -- to select the last menu item

            keystroke return

            delay 0.1

            keystroke return

        end tell

    end tell


    The three “delay 0.1” statements are just for caution and might possibly be removed.


     

    Message was edited by: Pierre L.

  • 7. Re: Applescript to start a private network
    personal_username Level 1 Level 1 (0 points)

    super! thanks a lot!

  • 8. Re: Applescript to start a private network
    Pierre L. Level 4 Level 4 (3,860 points)

    My pleasure. (I love easy questions like that.)