我正尝试在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)发布于 2019-07-04 17:30:48
以\n格式插入换行符,以\t格式插入水平制表符。另请参见link。
> print('1\t2\n3\t4')
1 2
3 4https://stackoverflow.com/questions/56882947
复制相似问题