Created
March 22, 2017 11:22
-
-
Save knu/997886c314b5c60865a7b3a11ef738de 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
-- www.lua: Hammerspoon snippet that takes a snapshot and uploads it to imagebin every time you hit "www". | |
-- | |
-- Requirements: | |
-- * ffmpeg | |
-- * imagebin API key | |
-- | |
-- This script is directly inspired by: http://portal.nifty.com/kiji/170321199097_1.htm | |
-- | |
-- License: BSD-2-Clause (c) Akinori MUSHA | |
do | |
-- git clone https://github.com/knu/hs-knu ~/.hammerspoon/knu | |
local knu = require("knu") | |
local guard = knu.runtime.guard | |
local imagebin_key = "your_api_key" | |
local function www() | |
hs.alert.show("www") | |
hs.execute([[ | |
. ~/.bash_profile | |
set -e | |
dir=$(mktemp -dt tmp) | |
pic=$dir/pic.jpg | |
ffmpeg -f avfoundation -video_size 1280x720 -framerate 30 -i 0 -vframes 1 "$pic" >/dev/null 2>&1 | |
url=$(curl -F key=]]..imagebin_key..[[ -F file="@$pic" https://imagebin.ca/upload.php | ruby -ne '$_.sub!(/^url:/, "") and print') | |
rm -rf "$dir" | |
open "$url" | |
]]) | |
end | |
local w = hs.keycodes.map["w"] | |
local count = 0 | |
guard(hs.eventtap.new( | |
{hs.eventtap.event.types.keyDown}, | |
function (e) | |
if e:getKeyCode() ~= w or | |
hs.fnutils.some(e:getFlags(), function (b) return b end) then | |
count = 0 | |
return false | |
end | |
count = count + 1 | |
if count >= 3 then | |
count = 0 | |
hs.timer.doAfter(0.1, www) | |
else | |
hs.timer.doAfter(0.5, function () | |
count = math.max(count - 1, 0) | |
end) | |
end | |
return false | |
end)):start() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment