Created
April 30, 2019 13:53
-
-
Save ahonn/32d129428c9213ccf0c29a42c6aa714f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clipboard = hs.chooser.new(function (choice) | |
if choice then | |
hs.pasteboard.setContents(choice.content) | |
hs.eventtap.keyStroke({ "cmd" }, "v") | |
end | |
end) | |
local history = {} | |
function addHistoryFromPasteboard() | |
local contentTypes = hs.pasteboard.contentTypes() | |
local item = {} | |
for index, uti in ipairs(contentTypes) do | |
if uti == "public.utf8-plain-text" then | |
local text = hs.pasteboard.readString() | |
item.text = string.gsub(text, "[\r\n]+", " ") | |
item.content = text; | |
break | |
end | |
end | |
table.insert(history, 1, item) | |
end | |
local preChangeCount = hs.pasteboard.changeCount() | |
local watcher = hs.timer.new(0.5, function () | |
local changeCount = hs.pasteboard.changeCount() | |
if preChangeCount ~= changeCount then | |
addHistoryFromPasteboard() | |
preChangeCount = changeCount | |
end | |
end) | |
watcher:start() | |
hs.hotkey.bind({ "cmd", "shift" }, "v", function () | |
clipboard:choices(history) | |
clipboard:show() | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment