9
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[macOS]コマンドラインからWebブラウザを開く方法

Posted at

やりたいこと

MacOS(v13.2)でコマンドラインから、Google ChromeなどのWebブラウザを起動したい、あるいは指定したURLを開きたい。

方法

アプリの絶対パスから起動する

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome

URLを引数に指定するとそのURLを開くことも可能。

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome https://www.google.com

新しいウィドウで開きたい場合は--args --new-windowオプションを指定する。

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --args --new-window https://www.google.com

※既存プロセスがない場合は、コマンドの実行後ターミナルを閉じたりCtrl+Cでコマンドを中止すると、Chromeが終了する。

「open」コマンドを使う

「open」コマンドの「-a」オプションで指定したアプリを開くことが可能。

open -a "Google Chrome" 

URLを引数に指定するとそのURLを開くことも可能。

open -a "Google Chrome" https://www.google.com

新しいウィドウで開きたい場合は-nと--args --new-windowオプションを指定する。

open -na "Google Chrome" --args --new-window https://www.google.com

aliasを作成する

頻繁に使用する場合はaliasを作成しておくと便利。

alias chrome='open -a "Google Chrome"'

上記の方法で-a(アプリ名)の引数を変更することで他のブラウザを起動することも可能。

open -a "Firefox" 

オプションなしで、URLのみ「open」コマンドの引数として指定した場合は、デフォルトブラウザが使われる。

open https://www.google.com/ 

ローカルにあるhtmlファイルを開き場合は引数としてファイルのパスを指定する。

open -a "Google Chrome" index.html
9
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?