LoginSignup
0
1

WEBサイト確認用にブラウザを複数ひらく

Last updated at Posted at 2024-02-04

はじめに

わたしは各デバイスでの表示を確認しながら制作をするタイプなのですが毎回ブラウザを3つくらい開いてそれぞれipad iPhone ・・・という感じでデベロッパーツールを設定しているわけです。
それ地味に面倒な作業だなとおもってシェルで起動できないかなと思い立った感じです。
まだ途中でブラウザで特定の位置に開くといった感じになってます。

Apple Script

ながれとしては、
Google chromeをアクティブにして http://xxxxx.test をひらく
これを3回繰り返し
1番目のウィンドウをAへ配置、
2番目のウィンドウをBへ配置、
3番目のウィンドウをCへ配置って感じに指定しました。

配置する位置については同じようにapple scriptで調べました。
一番上のChromeの配置が取得できると思います。

URLは引数で渡す・・・のような感じになればなおよいのですかね。

osascript -e 'tell application "System Events" to get properties of first window of application process "Google Chrome"' | tr ":" "\n" | grep -A 1 -e position -e size

# missing value, position
# 3282, 271, class
# --
#  - Google Chrome, size
# 557, 873, help
tell application "Google Chrome"
activate
repeat 3 times
open location "http://xxxxx.test"
set bounds of front window to {1, 1, 500, 900}
end repeat
end tell
delay .5
tell application "System Events" to tell process "Google Chrome"
tell front window
set size to {500, 900}
set position to {3840, 496}
end tell
tell second window
set size to {500, 900}
set position to {3265, 491}
end tell
tell third window
set size to {500, 900}
set position to {3844, -596}
end tell
end tell

スクリプトエディタよくわからないのでShell から操作することにしました。

Apple Script は osascript を使って実行できるようです。
コマンドを browser_open.sh などのファイルを作成して配置します。
これを sh browser_open.sh で実行することでブラウザを開けるはず。
ただ毎度 そんなファイル名やディレクトリを覚えていられないので alias で実行させます。

osascript \
-e "tell application \"Google Chrome\"" \
-e "activate" \
-e "repeat 3 times" \
-e "make new window" \
-e "open location \"http://xxxxx.test\"" \
-e "set bounds of front window to {1, 1, 500, 900}" \
-e "end repeat" \
-e "end tell" \
-e "delay .5" \
-e "tell application \"System Events\" to tell process \"Google Chrome\"" \
-e "tell front window" \
-e "set size to {500, 900}" \
-e "set position to {3840, 496}" \
-e "end tell" \
-e "tell second window" \
-e "set size to {500, 900}" \
-e "set position to {3265, 491}" \
-e "end tell" \
-e "tell third window" \
-e "set size to {500, 900}" \
-e "set position to {3844, -596}" \
-e "end tell" \
-e "end tell"

.bash_profile に実行コマンドを記述して .bash_profile を読み直します。ちなみにこれも面倒なので sb という感じで実行できるようにしています。

openb でブラウザが定位置に表示されました。たぶん。

.bash_profile
alias openb='sh ~/xxxx/browser_open.sh'
# sbで .bash_profile を読み直す場合
alias sb='source ~/.bash_profile'
source ~/.bash_profile

本当はデベロッパーツールも併せて起動したいとおもっているのでわかる方コメントやヒントをくださると助かります。

追記

ちょっと思いついたんですが自宅や会社でアプリの配置が違っているので(ディスプレイが自宅3枚、会社2枚といった感じで)ワークスペースを Apple Scriptで自宅配置、会社配置みたいにできれば楽そうですね! そのような機能があるか調べてもいないのであったらはずいですが・・
あ、ノート移動させて使っていたんです。

参考

https://genzouw.com/entry/2021/08/29/081919/2762/
https://abhp.net/it/IT_Google_Chrome_950000.html
https://ickx.hatenablog.com/entry/2020/09/22/021135
https://dev.classmethod.jp/articles/mac-app-resize/
https://webwork-plus.com/content/batch/batch-chrome-ps.html

0
1
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
0
1