Created
June 14, 2020 18:18
-
-
Save ivorscott/3ddba5527e5a96136bf870a57a37e721 to your computer and use it in GitHub Desktop.
Open file in default Mac browser
This file contains 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
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