deseven/iCanHazShortcut

Multiple hotkeys

Closed this issue · 8 comments

It would be awesome if I could assign multiple hotkeys to commands. For example, I would like to be able to open Desktop folder with Alt+D,D and the Documents folder with Alt+D,O and the Downloads folder with Alt+D,W. In the current version, I have to assign Alt+something for each folder.

As far as i know, there is no way to define such hotkeys system-wide.
The only way i can think of is to open a window (with Alt+D or whatever) which will grab focus to get an additional part (D,0,W, etc) of the hotkey.
Which may be not so convenient.

What if it was Alt+D, Alt+D? Would that be easier? i.e. Instead of running a command right away, waiting for a second keystroke if any of the commands has a second shortcut assigned?

Yes, that's easier and totally possible. However it requires a total rewrite of the way hotkeys are handled right now, along with interface additions.
I'll see what i can do, but no promises, sorry.

For now, you can easily emulate it.
Create a file in your home directory, call it, for example, openDir, set executable bit with chmod +x openDir.
Insert this code inside created file:

#!/bin/bash

if [ -z "$1" ]; then
    touch "$HOME/shouldOpen"
else
    if [ -f "$HOME/shouldOpen" ]; then
        rm -f "$HOME/shouldOpen"
        open "$1"
    fi
fi

Create main shortcut for ~/openDir.
Create secondary shortcut to open desired folder, for example ~/openDir ~/Downloads.

That way a folder will be opened only if you'll press main shortcut first.

I decided to do something really quick, so I've incorporated some basic AppleScript support to control shortcuts status.

You can now disable or enable needed shortcuts externally. Like that (editing the example i provided above):

#!/bin/bash

if [ -z "$1" ]; then
    touch "$HOME/shouldOpen"
    osascript -e 'tell application "iCanHazShortcut" to enable "⌥D"'
    osascript -e 'tell application "iCanHazShortcut" to disable "⌥S"'
else
    if [ -f "$HOME/shouldOpen" ]; then
        rm -f "$HOME/shouldOpen"
        open "$1"
        osascript -e 'tell application "iCanHazShortcut" to enable "⌥S"'
        osascript -e 'tell application "iCanHazShortcut" to disable "⌥D"'
    fi
fi

That way it will work exactly how you want - pressing one hotkey will activate another one (or more).

Closing because of lack of feedback.
Please reopen if you have something to add.

Thank you for the nice solution. Although this is a workaround (and I didn't have time to test it yet), it seems feasible (as long as you don't use the same shortcut multiple times). Thanks for the quick and amazingly helpful responses.

Starting from 0.8.1 you can actually control shortcuts by their IDs, that way it's completely possible to have the same shortcuts as many times as you want.

Just an app reference for multiple shortcuts, in case you want to pursue this in the future.