Created
February 7, 2025 15:24
-
-
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
This file contains hidden or 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
#!/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