Last active
April 6, 2016 17:33
-
-
Save jrolfs/3d06a1587d7a5c7fcac7761d6ffd2314 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env osascript -l JavaScript | |
| function run(argv) { | |
| var method; | |
| if (['connect', 'disconnect'].indexOf(argv[0]) > -1) { | |
| method = argv[0] | |
| } else { | |
| return console.log('Error: invalid method'); | |
| } | |
| try { | |
| var systemEvents = Application('System Events'); | |
| systemEvents[method](systemEvents.networkPreferences.services.whose({ name: 'My VPN' }); | |
| } | |
| catch (error) { | |
| if (error.errorNumber !== -1708) console.log(error); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment