Open an .html file with default browser using Bash on Mac

前端 未结 8 1633
陌清茗
陌清茗 2020-12-13 17:17

So, this is what I need :

Let\'s say I have an index.html file.

How do I tell the terminal to open it using the default browser?

(Using

相关标签:
8条回答
  • 2020-12-13 17:26

    from the directory containing index.html, try...

    open ./index.html
    

    the open command opens a file (or directory, or URL). open is included with MacOSx. specifics and options can be found using

    man open
    

    note: default application is determined via LaunchServices.

    0 讨论(0)
  • 2020-12-13 17:30

    i managed to open the html file with chrome by placing the file after the browser command. so,

    google-chrome-stable ./index.html
    

    although im not sure what the call would be to the default browser, if you knew it you could put it as an alias in your .bashrc and from then on, use whatever you called your alias, plus the file.

    goo ./index.html
    

    just my experience, first response

    0 讨论(0)
  • 2020-12-13 17:31

    You can use the open command with the -a flag to open a file or location in Chrome (or any target application):

    open -a "Google Chrome" index.html

    This also works with URLs, i.e. open -a "Google Chrome" http://www.apple.com.

    ---> I found this answer @ stack exchange, thanks to user "robmathers"

    0 讨论(0)
  • 2020-12-13 17:31

    To open the filename.html in the default browser use :

    open filename.html
    

    open is a very good command as well as a feature of Mac OS that makes me fall in love with it more deeper. It automatically chooses the appropriate default app to open the file.

    And in case you want to open a file in your desired app rather then default :

    open -a /Applications/Google\ Chrome.app filename.html
    

    The backslash \ after Google is used to escape the space character.

    Alternatively you can write :

    open -a "/Applications/Google Chrome.app" filename.html
    

    Hope this helps you ( I know I am very late ) and others !!!.

    0 讨论(0)
  • 2020-12-13 17:32

    In terminal you can run open index.html

    0 讨论(0)
  • 2020-12-13 17:39

    One simple method worked for me is firefox ./index.html

    0 讨论(0)
提交回复
热议问题