我已经从https://github.com/asmagill/hs._asm.undocumented.spaces安装了“无证空间”模块。特别是,它提供了一种方法moveWindowToSpace,我尝试使用该方法绑定cmd+1将当前窗口移动到空间 1,方法如下:
local spaces = require("hs._asm.undocumented.spaces")
function MoveWindowToSpace(sp)
local spaceID = spaces.query()[sp]
spaces.moveWindowToSpace(hs.window.focusedWindow():id(), spaceID)
spaces.changeToSpace(spaceID)
end
hs.hotkey.bind({"cmd"}, "1",function() MoveWindowToSpace(1) end)
Run Code Online (Sandbox Code Playgroud)
这是有效的,因为它将窗口移动到一个新的空间,但是,这些空间似乎是伪随机顺序的。
有谁知道如何将spaceIDs 返回的 s 正确映射spaces.query()到实际空间?
由于未记录的空格已移至空格,新代码如下(可以合并某些行,但我喜欢拆分操作的清晰度):
spaces = require("hs.spaces")
-- move current window to the space sp
function MoveWindowToSpace(sp)
local win = hs.window.focusedWindow() -- current window
local cur_screen = hs.screen.mainScreen()
local cur_screen_id = cur_screen:getUUID()
local all_spaces=spaces.allSpaces()
local spaceID = all_spaces[cur_screen_id][sp]
spaces.moveWindowToSpace(win:id(), spaceID)
spaces.gotoSpace(spaceID) -- follow window to new space
end
hs.hotkey.bind(hyper, '1', function() MoveWindowToSpace(1) end)
hs.hotkey.bind(hyper, '2', function() MoveWindowToSpace(2) end)
hs.hotkey.bind(hyper, '3', function() MoveWindowToSpace(3) end)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3818 次 |
| 最近记录: |