我正在尝试在 hammpersppon 中使用 lua 创建一个脚本。如果按“x”,用户将可以选择粘贴他们想要粘贴到 web 文本字段中的模板类型。
不幸的是,我无法弄清楚如何将该文本格式化为表格(带有行和列)?
我尝试将 google sheet (excel) 中的表格粘贴到 lua 代码中,但它仍然没有将其呈现为文本字段中的表格。
-- 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"] = "Option 1",
["subText"] = [[ Text 1 Text 2
Text 3 Text 4]]
},
{
["text"] = "Option 2",
["subText"] = [[ Text 1 Text 2
Text 3 Text 4]]
},
})
hs.hotkey.bind({"X"}, "X", function() chooser:show() end)