pslaboが試したことの記録

はてなダイヤリーからはてなブログに引っ越してきました

この日記は現在実行中の減量記録を含む個人的なメモとして始めましたが、最近はコンピュータやガジェット、ハック、セキュリティネタのほうがメインになっております。

はてなダイヤリー時代はカテゴリ分けが適当だったのですが、これはそのうち直します。


macOSの解像度をコマンドラインツールで変更する

macOSで画面の解像度を変更する場合は、通常は「システム環境設定」から行いますが、これは次のような操作は行なえません。

  • よく使う解像度に素早く切り替えたい
  • Retinaディスプレイでスケーリングを無効化した解像度に設定したい

自分にとっては、スケーリングの有効化、無効化は案外重要な要素で、例えばVMWare Fusion利用時にマウスクリックの位置がずれる問題への対処としてスケーリングを無効化するという方法を用いています。また外部ディスプレイとミラーリングするときに、外部ディスプレイ側の表示解像度が正しく行われないケースが確認できているため、その場合の対策として、同様にスケーリングを無効化していました。

この要件に対して、今までは QuickRes というソフトウェアを使っていました。 www.thnkdev.com

これで概ね要望は満たせるのですが、できればコマンドラインツールで変更したい、そう思っていたら GitHub で公開されている displayplacer がコマンドラインベースで解像度変更できることを知りました。

github.com

そこで、このツールのインストール手順と簡単な使用方法をメモとして残します。

必要な環境

HomeBrewの環境がない方は、次のページからバイナリがダウンロードできます。 https://github.com/jakehilborn/displayplacer/releases

ダウンロードしたバイナリをパスが通った場所に配置し、chmod +x しておきます。

HomeBrew の環境がある場合は brew tap jakehilborn/jakehilborn && brew install displayplacer でインストールできます。

使用方法

displayplacer list で利用可能な解像度一覧が取得できます。

% displayplacer list                 
Persistent screen id: (UUID)
Contextual screen id: mmmmmmmm
Type: MacBook built in screen
Resolution: 1440x900
Hertz: N/A
Color Depth: 4
Scaling:on
Origin: (0,0) - main display
Rotation: 0 - rotate internal screen example (may crash computer, but will be rotated after rebooting): `displayplacer "id:(UUID) degree:90"`
Resolutions for rotation 0:
  mode 0: res:1280x800 color_depth:4 scaling:on
  mode 1: res:1680x1050 color_depth:4 scaling:on
  mode 2: res:1440x900 color_depth:4 scaling:on <-- current mode
  mode 3: res:1024x640 color_depth:4 scaling:on
  mode 4: res:1280x720 color_depth:4 scaling:on
  mode 5: res:960x600 color_depth:4 scaling:on
  mode 6: res:960x540 color_depth:4 scaling:on
  mode 7: res:825x525 color_depth:4 scaling:on
  mode 8: res:720x450 color_depth:4 scaling:on
  mode 9: res:840x525 color_depth:4 scaling:on
  mode 10: res:2560x1600 color_depth:4
  mode 11: res:1280x800 color_depth:4
  mode 12: res:3360x2100 color_depth:4
  mode 13: res:2880x1800 color_depth:4
  mode 14: res:2048x1280 color_depth:4
  mode 15: res:2560x1440 color_depth:4
  mode 16: res:1920x1200 color_depth:4
  mode 17: res:1920x1080 color_depth:4
  mode 18: res:1280x720 color_depth:4
  mode 19: res:1650x1050 color_depth:4
  mode 20: res:1440x900 color_depth:4
  mode 21: res:1152x720 color_depth:4
  mode 22: res:1024x768 color_depth:4
  mode 23: res:840x524 color_depth:4
  mode 24: res:800x600 color_depth:4
  mode 25: res:640x480 color_depth:4
  mode 26: res:1680x1050 color_depth:4

Execute the command below to set your screens to the current arrangement:

displayplacer "id:(UUID) res:1440x900 color_depth:4 scaling:on origin:(0,0) degree:0"

"id:mmmmmmmm mode:20" のように実行すると、スケーリング無しの 1440x900 に設定できます。

ディスプレイの向きの回転や、複数ディスプレイを接続している場合のディスプレイ選択、細かい位置合わせも設定できるようですが、現状、そこまでの設定調整は不要なので、具体的な方法は未確認です。