Open the html binding page on Mac OS from the command line

I would like to open a web page for a specific anchor.

eg:

open index.html # intro

When I try to do this, I can get an error message

index.htm.l # intro does not exist

+6
source share
4 answers

It will not open because it thinks you are entering the file name index.htm.l#intro . As far as I can tell, you cannot open the page from the command line to the anchor.

As a workaround, you can enable javascript to go to the specified anchor using the onLoad function or jQuery document.ready function.

+2
source

You can also use the AppleScript command line (in terminal):

 osascript -e 'tell application "Safari" to open location "file://{full_path}/index.html#intro"' 

in which {full_path} is the absolute path to the file.

+2
source

As far as I can tell, this is impossible. Command:

 open file:///path/to/file.html#test 

successfully opens the specified HTML file in the default browser, but does not pass the #test binding to this file. However, the same thing works with the http:// URL. My suspicion is that the Apple Events used to process the file:// request indicate only the file name and not the URL, so the anchor cannot be saved.

0
source

The solution offered here automatically uses the default browser: https://apple.stackexchange.com/a/197284/202702

Nonspecific approach:

osascript -e 'open location "file:///Users/me/index.html#my-anchor"'

0
source

Source: https://habr.com/ru/post/943649/


All Articles