Skip to content

Instantly share code, notes, and snippets.

@mkutz
Created April 20, 2018 17:44
Show Gist options
  • Save mkutz/24222c06342d8e69b8091a9cf0ceab21 to your computer and use it in GitHub Desktop.
Save mkutz/24222c06342d8e69b8091a9cf0ceab21 to your computer and use it in GitHub Desktop.
Simple Groovy script to open an URL under Linux, as well as OSX or Windows.
#!/usr/bin/env groovy
/*
* define CLI
*/
def cli = new CliBuilder(usage: "${this.class.name} [options]")
cli.usage()
/*
* open URL
*/
String command = [
"windows": "start",
"linux": "xdg-open",
"darwin": "open"
].find { key, value -> System.properties["os.name"].toLowerCase().contains(key) }.value
Process process = "${command} \"${args.join()}\".execute()
process.consumeProcessOutput(System.out, System.err)
process.waitFor()
System.exit(process.exitValue())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment