Skip to content

Instantly share code, notes, and snippets.

@shollingsworth
Created February 7, 2025 15:24
Show Gist options
  • Save shollingsworth/66ee7e2730fad070adae784330a1726d to your computer and use it in GitHub Desktop.
Save shollingsworth/66ee7e2730fad070adae784330a1726d to your computer and use it in GitHub Desktop.
open a file in chrome on a mac, sometimes the open command doesn't open some files in a web browser, this helps with that
#!/usr/bin/env python3
"""Open a file in a web browser."""
import argparse
from pathlib import Path
from subprocess import check_call
def main() -> None:
"""Run main function."""
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description=__doc__,
add_help=True,
)
parser.add_argument(
"file",
help="file to open in browser",
type=str,
)
args = parser.parse_args()
file = Path(args.file).expanduser()
cmd = [
"open",
"-a",
"Google Chrome",
str(file),
]
check_call(cmd)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment