Skip to content

Instantly share code, notes, and snippets.

@stepango
Created May 23, 2022 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stepango/858507b16d74f729b14f8fad5c3482d7 to your computer and use it in GitHub Desktop.
Save stepango/858507b16d74f729b14f8fad5c3482d7 to your computer and use it in GitHub Desktop.
-- Layout Switch
ctrlPressed = false
keyPressed = false
eventTypes = hs.eventtap.event.types
events = { eventTypes.flagsChanged, eventTypes.keyUp }
function indexOf(table, value)
local index = -1
for i = 1, #table do
if value == table[i] then
return index
end
end
end
layouts = hs.keycodes.layouts()
layout = hs.keycodes.currentLayout()
current_index = indexOf(layouts, layout)
right_command_key = 0x36
layoutWatcher = hs.eventtap.new(events, function(e)
local flags = e:getFlags()
local keyCode = e:getKeyCode()
if flags.cmd and keyCode == right_command_key and not (flags.alt or flags.shift or flags.ctrl or flags.fn) then
ctrlPressed = true
keyPressed = false
elseif ctrlPressed and not (flags.cmd or flags.alt or flags.shift or flags.ctrl or flags.fn) and not keyPressed then
ctrlPressed = false
if keyCode == right_command_key then
current_index = (current_index % #layouts) + 1
hs.keycodes.setLayout(layouts[current_index])
end
else
keyPressed = true
end
end)
layoutWatcher:start()
-- Periodic Things
hs.timer.doAt("00:00", "1h", function()
hs.application.launchOrFocus("Things3")
end):start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment