summaryrefslogtreecommitdiff
path: root/hammerspoon/init.lua
blob: b3703128d9bf79a7b90c84b75f6578b09fdd8030 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
-- 这个脚本在 MacBook 接入外接显示屏时
-- 将 Dock 栏移动到右侧
local function updateDockPosition()
    local screens = hs.screen.allScreens()
    local dockPos = "bottom"
    local autoHide = true
    local foundExternal = false

    -- 查找名为 "P5" 的外接屏
    for _, s in ipairs(screens) do
        if s:name() == "P5" then
            foundExternal = true
            break
        end
    end

    if foundExternal then
        dockPos = "right"
        autoHide = true
    else
        dockPos = "bottom"
        autoHide = true
    end

    local cmd = string.format(
        'defaults write com.apple.dock orientation %s; ' ..
        'defaults write com.apple.dock autohide -bool %s; ' ..
        'killall Dock',
        dockPos,
        autoHide and "true" or "false"
    )

    hs.execute(cmd)
end

local screenWatcher = hs.screen.watcher.new(updateDockPosition)
screenWatcher:start()

updateDockPosition()