personal_username

Q: Applescript to start a private network

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)

Posted on Apr 27, 2012 12:20 AM

Close

Q: Applescript to start a private network

  • All replies
  • Helpful answers

  • by MrHoffman,

    MrHoffman MrHoffman Apr 27, 2012 9:35 AM in response to personal_username
    Level 6 (15,612 points)
    Mac OS X
    Apr 27, 2012 9:35 AM in response to personal_username

    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.)

  • by Camelot,

    Camelot Camelot Apr 27, 2012 9:40 AM in response to personal_username
    Level 8 (47,233 points)
    Mac OS X
    Apr 27, 2012 9:40 AM in response to personal_username

    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.

  • by personal_username,

    personal_username personal_username Apr 27, 2012 8:43 PM in response to personal_username
    Level 1 (0 points)
    Apr 27, 2012 8:43 PM in response to personal_username

    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!

  • by MrHoffman,

    MrHoffman MrHoffman Apr 28, 2012 4:49 AM in response to personal_username
    Level 6 (15,612 points)
    Mac OS X
    Apr 28, 2012 4:49 AM in response to personal_username

    Maybe?

     

    #!/bin/bash

    networksetup -createnetworkservice {networkservicename} {hardwareport}

  • by personal_username,

    personal_username personal_username Apr 28, 2012 9:23 AM in response to MrHoffman
    Level 1 (0 points)
    Apr 28, 2012 9:23 AM in response to MrHoffman

    not sure what to put on hardwareport...

  • by Pierre L.,Solvedanswer

    Pierre L. Pierre L. Apr 28, 2012 9:51 AM in response to personal_username
    Level 5 (4,484 points)
    Apr 28, 2012 9:51 AM in response to personal_username

    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.

  • by personal_username,

    personal_username personal_username Apr 28, 2012 9:57 AM in response to Pierre L.
    Level 1 (0 points)
    Apr 28, 2012 9:57 AM in response to Pierre L.

    super! thanks a lot!

  • by Pierre L.,

    Pierre L. Pierre L. Apr 28, 2012 10:38 AM in response to personal_username
    Level 5 (4,484 points)
    Apr 28, 2012 10:38 AM in response to personal_username

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

  • by farhanfrombatam,

    farhanfrombatam farhanfrombatam Jun 24, 2016 4:01 PM in response to personal_username
    Level 1 (13 points)
    Mac OS X
    Jun 24, 2016 4:01 PM in response to personal_username

    image.png