0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Mac] Automatorとdisplayplacerコマンドを使ってディスプレイ解像度を切り替えるアプリケーションを作る

Last updated at Posted at 2025-04-23

はじめに

筆者は在宅勤務環境でUWQHD(解像度:3440×1440)のディスプレイを使用しています。ウィンドウを2つ並べても十分な表示領域を確保できて便利ですが、Web会議でこの解像度の画面を共有すると、横に長く小さく表示されてしまうという不便さもあります。
画面を共有するたびにMacのシステム設定から解像度を切り替えるのは非常に面倒なため、Automatorから displayplacerコマンドを実行して解像度を切り替えるアプリケーションを作成します。

前提

後述するShellスクリプトで使用するdisplayplacerとggrep(GNU grep)コマンドは、Macには標準で含まれていないため、事前にHomebrewなどでインストールしておく必要があります。

Script

まずは、次のようなShellスクリプト(.shファイル)を作成し、動作を確認します。
解像度の切り替えは、3440×1440(アスペクト比21:9)と2560×1440(アスペクト比16:9)を交互に切り替える形式です。
この環境では、Homebrewをホームディレクトリ以下にインストールしています。そのため、displayplacerコマンドおよびggrepコマンドはフルパスで記述します。これは、brewのbin(実行ファイルフォルダ)にパスを通しても、Automatorに組み込んだ際に環境パスが反映されないためです。
なお、コマンドのフルパス、解像度、ディスプレイのUUIDなど、displayplacerの引数は各自の環境に合わせて適宜修正してください。ディスプレイのUUIDは、displayplacerをlistオプション付きで実行すれば確認できます。

sh
#!/bin/zsh

curres=$(/Users/username/.homebrew/bin/displayplacer list | grep 'current mode' | /Users/username/.homebrew/bin/ggrep -oP 'res:\K[^ ]+')

if [[ $curres == "3440x1440" ]] then
	/Users/username/.homebrew/bin/displayplacer "id:<UUID> res:2560x1440 hz:144 color_depth:8 enabled:true scaling:off origin:(0,0) degree:0"
else
    /Users/username/.homebrew/bin/displayplacer "id:<UUID> res:3440x1440 hz:144 color_depth:8 enabled:true scaling:off origin:(0,0) degree:0"
fi

Automatorでアプリ化

Shellスクリプトが正常に動作したら、次はAutomatorを使ってアプリ化します。
まず、Automatorを起動して新規アプリケーションを作成し、アクションの種類として「シェルスクリプトを実行」を選択します。そこに、先ほど作成したShellスクリプトの内容を貼り付け、適当な名前を付けてアプリケーションとして保存します。

Automator_SRapp.png

このアプリケーションをDockに登録しておけば、クリックするだけで瞬時に解像度を切り替えられるようになります。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?