阅读220 返回首页    go iPhone_iPad_Mac_apple


terminal open

Due to using a Mac in a corporate environment where we were prevented from upgrading to Sierra (10.12.x) for what seems like forever, it's taken me a while to realize that an option to a command I used to use frequently on Leopard, Snow Leopard, Lion, Mountain Lion, Mavericks and finally El Capitan no longer exists in Sierra.

 

Frequently, I'd want/need to open the same locally generated web content in various browsers to test browser compatibility.  Rather than open each browser and then use File > Open to browse to my file, I would use the Terminal utility and use this bash command to open the same file in multiple browsers.

 

for app in Safari Firefox.app Chrome.app; do open -a $app ~/Documents/some_web_page.html; done

 

The for loop would execute three commands:

open -a Safari ~/Documents/some_web_page.html

open -a Firefox.app ~/Documents/some_web_page.html

open -a Chrome.app ~/Documents/some_web_page.html

 

Which would result in 3 windows, one for each browser, opening the file ~/Documents/some_web_page.html

 

After upgrading to Sierra, when running the command 'open -a <app> <file>', I get this error:

open: invalid option -- 'a'

Usage: open [OPTIONS] -- command

 

This utility help you to start a program on a new virtual terminal (VT).

 

Options:

  -c, --console=NUM   use the given VT number;

  -e, --exec          execute the command, without forking;

  -f, --force         force opening a VT without checking;

  -l, --login         make the command a login shell;

  -u, --user          figure out the owner of the current VT;

  -s, --switch        switch to the new VT;

  -w, --wait          wait for command to complete;

  -v, --verbose       print a message for each action;

  -V, --version       print program version and exit;

  -h, --help          output a brief help message.

 

Why would Apple remove the ability to specify a non-default application to open a file?  The ability to open web page using the non-default browser is a pain when using the GUI.



As an individual command entered into terminal:

open -a <application> <link>

seems to execute as expected;

 

see :

man open | more



Open works with Sierra just like it always did. Try 'man open'. You've probably mangled your path.

 

cdhw$ which open

/usr/bin/open

MacWilliams:~ cdhw$ open --help

open: unrecognized option `--help'

Usage: open [-e] [-t] [-f] [-W] [-R] [-n] [-g] [-h] [-s <partial SDK name>][-b <bundle identifier>] [-a <application>] [filenames] [--args arguments]

Help: Open opens files from a shell.

      By default, opens each file using the default application for that file. 

      If the file is in the form of a URL, the file will be opened as a URL.

Options:

      -a                Opens with the specified application.

      -b                Opens with the specified application bundle identifier.

      -e                Opens with TextEdit.

[...]



The Apple /usr/bin/open command has not lost the -a option in my installations of El Capitan, Sierra, or High Sierra.



最后更新:2017-10-19 02:31:45

  上一篇:go Need to convert PXM file without having to buy ...
  下一篇:go Pathway to a folder via VPN