Skip to content

[MacOS] 分割視窗左右的設定方法

自從我將主要工作環境從 Linux 搬到 MacOS 上後,我一直都想要找到一個方法能夠使用快捷鍵來將視窗『快速地配置到左/右半邊螢幕』。畢竟我很需要同時看兩個視窗。

現在我主要是透過 SizeUp 這個軟體來做到這件事的。不過這個軟體雖然能滿足我的要求,但是它偶爾會跳出需要授權的視窗,需要等待 5 秒才能將其關閉。

這讓我覺得很麻煩,所以我一直在研究怎麼透過 AppleScript 來實現這個功能。這其實就是 AppleScript 調整視窗大小的一點延伸,將指定的 application 設定成了在圖形化介面最上方的應用程式。

但結論是:透過 Automator 製作的快捷鍵(shortcut),其實還是很慢,這可能是一個 MacOS 已知的 BUG。


AppleScript 腳本

MOVE TO LEFT

set frontApp to (path to frontmost application as Unicode text)
set appHeight to 900
set appWidth to 720


tell application frontApp
	activate
	reopen
	set yAxis to 0
	set xAxis to 0
	set the bounds of the first window to {xAxis, yAxis, appWidth + xAxis, appHeight + yAxis}
end tell


MOVE TO RIGHT

set frontApp to (path to frontmost application as Unicode text)
set appHeight to 900
set appWidth to 720


tell application frontApp
	activate
	reopen
	set yAxis to 0
	set xAxis to 720
	set the bounds of the first window to {xAxis, yAxis, appWidth + xAxis, appHeight + yAxis}
end tell



製作快捷鍵

Step 1: 打開 Automator 製作腳本


Step 2: 選擇 Quick Action


Step 3: 選擇 Run AppleScript 並將腳本寫入 on run {input, parameters} 底下

之後別忘了儲存成你想要的名字。


Step 4: 打開 Finder 搜尋是否有這個檔案

雙擊安裝,並在 Library/Services 底下確認有這個檔案的 .workflow 檔案。


Step 5: 設定『快捷鍵』跟『權限』

從『左上角蘋果圖示』-> System Preferences… -> Keyboard -> Shortcuts


先進 Services 設定快捷鍵。


再去 App Shortcut 點 + 按鈕設定。

  • Application: All Applications
  • Menu Title: Services 裡你設定的快捷鍵名稱
  • Keyboard Shortcut: 你要的快捷鍵

設定完成之後,應該能正常運作了。


References


Read More

Leave a Reply