gpt4 book ai didi

lua - 在 hammerspoon 中粘贴 hs.chooser 中的文本

转载 作者:行者123 更新时间:2023-12-05 03:00:29 25 4
gpt4 key购买 nike

我正在尝试创建一个快捷方式,通过使用 hs.chooser 来存储一组文本模板。并且,用户可以通过单击 hs.chooser 的下拉菜单来粘贴它。

我使用下面的代码来显示我的模板但不粘贴文本。

谁能指出我做错了什么?

hs.hotkey.bind({"Q"}, "W", function()
local current = hs.application.frontmostApplication()

local chooser = hs.chooser.new(function(choice)
if not choice then focusLastFocused(); return end
hs.pasteboard.setContents(choice["chars"])
focusLastFocused()
hs.eventtap.keyStrokes(hs.pasteboard.getContents())
end)

chooser:queryChangedCallback(function(string)
local choices = {
{
["text"] = "Testing",
["subText"] = "Testing my text"
}
}
chooser:choices(choices)
end)

chooser:searchSubText(true)

chooser:show()
end)

最佳答案

我想出了答案

-- Focus the last used window.

local function focusLastFocused()
local wf = hs.window.filter
local lastFocused = wf.defaultCurrentSpace:getWindows(wf.sortByFocusedLast)
if #lastFocused > 0 then lastFocused[1]:focus() end
end
-- On selection, copy the text and type it into the focused application.

local chooser = hs.chooser.new(function(choice)
if not choice then focusLastFocused(); return end
hs.pasteboard.setContents(choice["subText"])
focusLastFocused()
hs.eventtap.keyStrokes(hs.pasteboard.getContents())
end)

chooser:choices({
{
["text"] = "Browser\n",
["subText"] = "I used these browsers",
},
{
["text"] = "Device\n",
["subText"] = "I used these devices",
},

})
hs.hotkey.bind({"E"}, "E", function() chooser:show() end)

关于lua - 在 hammerspoon 中粘贴 hs.chooser 中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56751409/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com