MacでDockにしまったWindowを復元するショートカットを作った
Cmd + M で「しまう」のショートカットがMacでは共通してあるわけだが、逆に戻すショートカットが無い。
ゴテゴテとウィンドウが重なっている状態があまり好きじゃなくて、都度「しまう」を行っていたりするわけだけど、Cmd + Tab でアプリケーションを切り替えた後、元に戻すのにマウスポインタを動かす必要が出てきて QoL が下がっていた。
ということで、ショートカットを作ろうと努力をしてみたよ。(完全ではないけど概ね動く)
やったこと
- Automator で AppleScript を動かすサービスを作る
- システム環境設定 -> キーボード -> ショートカット の「サービス」からショートカットを割り当てる
Automator で AppleScipt
起動
種類を聞かれるので、「サービス」を選ぶ
AppleScript
on run {input, parameters}
tell application "System Events"
set frontApplication to a reference to (processes whose visible is true and frontmost is true)
if (count frontApplication) is 0 then return
set appId to bundle identifier of (item 1 of frontApplication)
end tell
tell application id appId
set hiddenWindows to a reference to (windows whose miniaturizable is true and miniaturized is true)
try
if (count hiddenWindows) is not 0 then
set miniaturized of hiddenWindows to false
end if
on error msg number n
activate
display dialog msg
end try
end tell
return input
end run
やっていること
- System Events から最も全面にあるアプリケーションのidを得る
- 得たidのアプリケーションの内、「しまう」ことができるもの、かつ、しまわれた状態のWindowリストを得る
- そのWindowリストに対して、
miniaturizedを false に設定する(しまわれた状態を元に戻す)
しまわれたウィンドウを一つ一つ戻すこともできるだろうけど、そのアプリケーションのは全て戻すほうが使い勝手が良いかな(?)と思ってそうしている。