Get Keystrokes to Pass to Script as Arguments

34 views
Skip to first unread message

Sean Mackesey

unread,
Jan 29, 2013, 7:47:40 PM1/29/13
to keym...@googlegroups.com
I'm wondering whether it's possible to retrieve the last few keystrokes to pass as an argument to a script.  The application I have in mind is to make a flexible shortcut for splitting the screen between two apps.  Basically I would like to do:

map <PREFIX>XY, `path_to_my_script X Y`

Where PREFIX is an arbitrary leading sequence.  The X and Y keystrokes following the prefix would be passed to a script as command line arguments.  The script would map them to particular application names and execute the appropriate applescript to split the screen between them.  I know that I could do this by generating a large number of mappings in the keymandorc file using Ruby, but I've experimented before with generating mappings for an entire combinatoric space (trying to allow numeric arguments for text motions a la Vim) and it made the latency of keystrokes unbearably long.  There's not too many pairs of applications, so that probably wouldn't be a problem here, but this is a general problem I'd like to know how to solve for the future.

Jean-Paul Boodhoo

unread,
Feb 2, 2013, 10:51:17 AM2/2/13
to keym...@googlegroups.com
Hey Sean,

Do you want to split the screen between 2 currently running apps, or to split the screen between 2 apps that you will also have Keymando launch?

JP


--
You received this message because you are subscribed to the Google Groups "Keymando" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keymando+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
God Bless You,

JP

Develop With Passion®
web site: http://www.developwithpassion.com
blog: http://blog.developwithpassion.com
email: j...@developwithpassion.com
phone: (503)213-3507

Jean-Paul Boodhoo

unread,
Feb 2, 2013, 1:47:42 PM2/2/13
to keym...@googlegroups.com
Hey Sean,

Keymando has the api to do full window management also (move windows to different quadrants of the screen, cycle between monitors, nudge the windows etc, along with a host of other app manipulation items).

Once I have 2 applications open I will just usually do the following:

1. Run the Focus Application Command and pick the App I want to focus
2. Run the Move Window To Left Command (after this I will Run The Last Command, to cycle it to the monitor I want it to be on).
3. Run the Focus Application Command and pick the second App
4. Run the Move Window To Right Command (again Running the Last Command, to cycle it to the monitor where the other app is).

Yes you can write a script that does all of this. Personally, I prefer to keep my mappings shallow and leverage the command system so I can just bring up the Run Registered Command window and do all of that stuff.

If you take a look at my Keymando files (http://github.com/developwithpassion/keymando_files), you can see how basic the mappings are. The most important ones being these:

map "<Cmd-d>", Commands.current_app_windows #pops up a selection box where I can trigger a specific window for the currently focused app
map "<Cmd-f>", Commands.trigger_app  #this pops up a selection box where you can choose which app you want to focus, I use this rather than osx's app switcher, as it gives me the type ahead, and I can go straight to the app I want (useful when you have lots of apps running)
map "<Cmd- >", Commands.run_registered_command  #the most important mapping I have, this pops up a dialog box where I can typeahead and choose to run any of the predefined or my own custom commands
map "<Cmd-o>", Commands.run_last_command #repeat the last command that was run (useful when I am doing things like moving windows, increasing/decreasing voluming, or nudging windows by increments)
map "<Cmd-r>", Commands.right_click #not much to say about that one!
map "<Cmd-i>", Commands.run_history_item #pick from a list of commands I have run recently and rerun it
map "<Cmd-p>", Commands.press_button_on_ui #highlight elements on the ui and have the element pressed

except /(iTerm|MacVim)/ do
  map ";lc", Commands.left_click_element #highlight elements on the ui (hit-a-hint style), type in the characters for an element and have it left-click the element
  map ";rc", Commands.right_click_element #highlight elements on the ui (hit-a-hint style), type in the characters for an element and have it right-click the element
  map ";dc", Commands.double_click_element #highlight elements on the ui (hit-a-hint style), type in the characters for an element and have it double-click the element
  map ";mi", Commands.show_current_app_menu_items #show the current app menu items, type ahead and choose the one you want to click on
end


Anyway, as you are already aware. We have still not documented a lot of this stuff, but hopefully, if you take a look at the scripts it will give you some ideas that you may be able to accomplish without gratuitous mapping.

God Bless You,

JP




Sean Mackesey

unread,
Feb 26, 2013, 12:41:06 PM2/26/13
to keym...@googlegroups.com
Hey Jean-Paul,

Thanks for such a thorough response!  Sorry for taking so long to get back to you.  I've taken your advice and have been looking into Keymando's command system but am running up against some difficulties.  I have some questions/comments:

- I recognize that the toggle needs to be set differently than other mappings (because it has to work when Keymando is disabled), but, for the sake of consistency, it would be nice to be able to set this like any other mapping
- It would be nice to have an official documentation listing of all the commands that keymando comes with
- Please elaborate in the "Commands" section of the docs when you say that commands can be accessed in scripts via Command[:name_of_command].  It would be good to have an example of how to use this there-- by testing it out I see it can be used to map key sequences to commands, but it is not the form that you use in your keymando files (and in the example you give above), which is instead `Commands.name_of_command`.  Also, in the current docs there is no example of directly mapping a key sequence to a command at all.
- I have this mapping:

map "<F6>", Commands.run_registered_command

and whenever I reload the keymandorc file, the run_registered_command window pops up unbidden.

- Mapping window resizing commands to key sequences appears to be broken, I think because there is a hyphen in the symbolized names of the resize commands?  I tried all the following and none of them work:

map "<F11>", Commands[:'window_-_move_to_left']
map "<F11>" do Commands[:'window_-_move_to_left'] end
map "<F11>", Commands.window_-_move_to_left
map "<F11>" do Commands.window_-_move_to_left end
map "<F11>", window_-_move_to_left
map "<F11>" do window_-_move_to_left end
map "<F11>" do Commands[:"window_-_move_to_left"] end

- I am confused about when I have to use a block and when I can pass a second argument to map.  Are the only valid second arguments Commands and key sequence strings?
- Finally, even slightly improved error messages could go a long way.  Bad mappings seem to silently fail or explode with cryptic nil-class errors.

All that said, I use Keymando every day and love it.  I hope it matures into something stable, easy-to-use, and well-documented.

Thanks
Sean

kl...@klean.dk

unread,
Sep 30, 2013, 5:48:07 AM9/30/13
to keym...@googlegroups.com
Hey I have the same problem - is it solved yet?
Reply all
Reply to author
Forward
0 new messages