Skip to content

Instantly share code, notes, and snippets.

@jrolfs
Last active April 6, 2016 17:33
Show Gist options
  • Select an option

  • Save jrolfs/3d06a1587d7a5c7fcac7761d6ffd2314 to your computer and use it in GitHub Desktop.

Select an option

Save jrolfs/3d06a1587d7a5c7fcac7761d6ffd2314 to your computer and use it in GitHub Desktop.
#!/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