Skip to content

Instantly share code, notes, and snippets.

@ivorscott
Created June 14, 2020 18:18
Show Gist options
  • Save ivorscott/3ddba5527e5a96136bf870a57a37e721 to your computer and use it in GitHub Desktop.
Save ivorscott/3ddba5527e5a96136bf870a57a37e721 to your computer and use it in GitHub Desktop.
Open file in default Mac browser
func preview(fname string) error {
const GOOS string = runtime.GOOS
switch {
case GOOS == "darwin":
if err := exec.Command("open", fname).Start(); err != nil {
return err
}
default:
// Locate the firefox browser in the PATH
browserPath, err := exec.LookPath("firefox")
if err != nil {
return err
}
// Open the file in the browser
if err := exec.Command(browserPath, fname).Start(); err != nil {
return err
}
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment