-- 这个脚本在 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()