system-wide hotkey

Any wishes
buzy
Posts: 16
Joined: Thu Dec 10, 2020 7:14 pm

system-wide hotkey

Post by buzy » Sat Dec 12, 2020 8:40 pm

Is it possible to make a system-wide hotkey to show/hide Nimble Commander like the one iTerm has? I find it very useful to be able to hide the iTerm window or make it the active window no matter what application is currently active with a single shortcut and I think Nimble Commander would be even more useful with such a hotkey than it already is.

New user of Nimble Commander and so far I love it.

User avatar
mike
Posts: 1060
Joined: Thu Jul 16, 2015 5:35 am
Location: Exeter, UK

Re: system-wide hotkey

Post by mike » Sun Dec 13, 2020 9:35 pm

Hi buzy,
I haven't don't it myself, but I'm pretty sure it's possible to achieve by using Automator and Apple Script.
There's no need to add anything to NC for this functionality.

buzy
Posts: 16
Joined: Thu Dec 10, 2020 7:14 pm

Re: system-wide hotkey

Post by buzy » Mon Dec 14, 2020 4:42 pm

Thanks for the fast response. I haven't used Automator and Apple Script so far but I'll try it out once I don't have as many projects from school and have more free time.

JayB
Posts: 192
Joined: Sun Jan 08, 2017 4:38 pm

Re: system-wide hotkey

Post by JayB » Tue Dec 15, 2020 11:30 pm

The AppleScript is super simple:

Code: Select all

tell application "Nimble Commander" to activate
If NC is running, it will come into foreground, and if it's not running, it will be launched instead. The same can be done with a shell script:

Code: Select all

open -a "Nimble Commander"
Put either of those in an Automator workflow, either as "Run AppleScript" or as "Run Shell Script", and set a keyboard shortcut in System Preferences.

However, Automator is super slow, and it also adds that hideous icon in your menu bar, so a global hotkey to toggle NC would be a nice feature, and it doesn't seem very complicated to do: https://dev.to/mitchartemis/creating-a- ... swift-25e9

However, you also have a quick way to switch with CMD-TAB, then hold the CMD key and use the arrow keys to navigate. Or alternatively with ALT-TAB, if you're using AltTab: https://github.com/lwouis/alt-tab-macos/

If you have a TouchBar, you can use TouchSwitcher: https://hazeover.com/touchswitcher.html… or use BetterTouchTool and program your own global touchbar button to toggle NC from anywhere in any app with one of the above one-liners: https://folivora.ai/

buzy
Posts: 16
Joined: Thu Dec 10, 2020 7:14 pm

Re: system-wide hotkey

Post by buzy » Sun Dec 20, 2020 3:24 pm

Thanks for all the options JayB. I've been using CMD+TAB so far. Closing and opening NC with spotlight every time you need it isn't that bad either considering how snappy NC is :)

JayB
Posts: 192
Joined: Sun Jan 08, 2017 4:38 pm

Re: system-wide hotkey

Post by JayB » Sat Jan 30, 2021 2:24 am

A good framework to include for a global shortcut would be MASShortcut: https://github.com/shpakovski/MASShortcut

Since NC is also available on the MAS, that could maybe be an option. I have a couple of apps installed that use it (MAS like Twitterrifc and non-MAS like Command-Q).

buzy
Posts: 16
Joined: Thu Dec 10, 2020 7:14 pm

Re: system-wide hotkey

Post by buzy » Sat Jan 30, 2021 10:52 am

@JayB Do you know if iTerm also uses it?

JayB
Posts: 192
Joined: Sun Jan 08, 2017 4:38 pm

Re: system-wide hotkey

Post by JayB » Sat Jan 30, 2021 5:32 pm

Doesn't look that way. Does iTerm even register system-wide keyboard shortcuts?

buzy
Posts: 16
Joined: Thu Dec 10, 2020 7:14 pm

Re: system-wide hotkey

Post by buzy » Sat Jan 30, 2021 5:42 pm

Yes it does:
Attachments
Screenshot 2021-01-30 at 19.38.55.jpg
Screenshot 2021-01-30 at 19.38.55.jpg (78.24 KiB) Viewed 10268 times

JayB
Posts: 192
Joined: Sun Jan 08, 2017 4:38 pm

Re: system-wide hotkey

Post by JayB » Sun Jan 31, 2021 12:04 am

Oh, yeah: it seems iTerm is using CGSInternal (third-party): https://gitlab.com/gnachman/iterm2/-/tr ... GSInternal
…the file CGSHotKeys.h is surely relevant.

Locked