System-wide hotkey to focus NC

Any wishes
Locked
sasha
Posts: 168
Joined: Wed Feb 17, 2016 4:59 pm

System-wide hotkey to focus NC

Post by sasha » Tue Jan 17, 2017 9:51 am

What do you think about an option for a system-wide hotkey to put NC into focus? I'm thinking something like Win+E for Explorer in Windows. I always found this very useful and it's quicker than Cmd+Tab when there's a lot of open apps. A good example in OSX would be iTerm2.

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

Re: System-wide hotkey to focus NC

Post by JayB » Wed Jan 18, 2017 9:11 am

Cool idea. Until there's a solution, you can do this yourself with a Service: open Automator > New > Service > no input + any application > run AppleScript OR run Shell Script:

Code: Select all

tell application "Nimble Commander" to activate
OR

Code: Select all

osascript -e 'tell application "Nimble Commander" to activate'
> save the Service, give it a nice name, then go to Services Preferences, find your new Service in the long list, and then define a keyboard shortcut for it; it will be available system-wide, so you need to check that there aren't any conflicts; you can use apps like CheatSheet for that. (My suggestion: keyboard shortcuts using CTRL+ALT+CMD plus a key are probably the safest to use.)

In AppleScript there's also a way to bring an app to the foreground

Code: Select all

tell application "System Events" to set frontmost of process "Nimble Commander" to true
but that will only work, if NC is already running, so you need the activate command too (see above).

The only downside is that macOS Services are a little slow; the fastest way would be to do it with an app extension, that only registers a system-wide keyboard shortcut, either directly from within the Nimble Commander bundle (that would be something for mike to develop eventually), or with a third party app extension that just addresses NC and brings it to the front (this you could do yourself, if you know Objective-C or Swift).

sasha
Posts: 168
Joined: Wed Feb 17, 2016 4:59 pm

Re: System-wide hotkey to focus NC

Post by sasha » Wed Jan 18, 2017 9:38 am

JayB wrote:
Wed Jan 18, 2017 9:11 am
Cool idea. Until there's a solution, you can do this yourself with a Service
Thanks, this works. As you said, this solution has a noticeable delay, about 1 second on my MBP.

@Mike: A native solution that works instantly would be nice to have.

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

Re: System-wide hotkey to focus NC

Post by mike » Thu Jan 19, 2017 3:24 am

I like this idea.
However, I don't think it'll be wise to put this functionality inside NC itself, since MAS-versions of NC cannot intercept keystrokes (Hello, Apple's sandbox ideology!), thus this feature will be crippled by design.
Said that, I can write a tiny separate app, that will do just that - catch keystroke, compare it with defined hotkey and set focus to defined application.
BTW, aren't plenty of such solutions available already?

sasha
Posts: 168
Joined: Wed Feb 17, 2016 4:59 pm

Re: System-wide hotkey to focus NC

Post by sasha » Thu Jan 19, 2017 5:08 pm

mike wrote:
Thu Jan 19, 2017 3:24 am
I like this idea.
Cool!
mike wrote:
Thu Jan 19, 2017 3:24 am
I can write a tiny separate app, that will do just that...
I think a "NC helper" app just for this case would be overkill. I'm using global hotkeys for apps like Things, iTerm2 or Little Snitch, they all have a shortcut recorder in their preferences without a helper app. I wouldn't mind the App Store version not supporting this feature, and this wouldn't be the only difference to the non-MAS version.
mike wrote:
Thu Jan 19, 2017 3:24 am
BTW, aren't plenty of such solutions available already?
You're right, it's easy to set up with third party tools. I've settled for a BetterTouchTool shortcut running the aforementioned AppleScript line almost instantaneous, much faster than using Services. Probably more people would use the feature if it was possible to set up in NC's preferences, as with the other apps I've mentioned. But no need to rush, this is certainly something that can wait a release or two :)

Locked