Skip to content

Instantly share code, notes, and snippets.

@swissmanu
Created August 14, 2013 08:52
Show Gist options
  • Save swissmanu/6229143 to your computer and use it in GitHub Desktop.
Save swissmanu/6229143 to your computer and use it in GitHub Desktop.
a quck'n'dirty prototype for chaining more than one command to a key/modifier combination for the zephyros window manager.
require '/Applications/Zephyros.app/Contents/Resources/libs/zephyros.rb'
require 'time'
@last_time = Time.now - 10
@times = 0
##
# Simply returns a Proc instance with the passed block.
def command
Proc.new
end
##
# Binds a list of Proc objects to a specific key/modifier combination. You can
# iterate over them by pressing the key/modifier combination repeatedly.
def bind_chained_commands(key, modifiers, chained_commands=[])
API.bind key, modifiers do
index_in_chain = index_in_chain chained_commands.size
chained_commands[index_in_chain].call
end
end
##
# Returns an increasing index number when called continously with a delay <= 1s.
#
# Pass number_of_commands to limit the maximum index returned.
def index_in_chain(number_of_commands=0)
now = Time.now
if @last_time >= now - 1
# Iterate through the chain
@times += 1
@times = 0 if number_of_commands <= @times
else
# Begin a new chain iteration
@times = 0
end
@last_time = now
return @times
end
bind_chained_commands 'D', ['Cmd', 'Shift'], [
command {
API.alert 'proc 1'
}, command {
API.alert 'proc 2'
}, command {
API.alert 'proc 3'
}
]
wait_on_callbacks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment