AppKitFocusOverlay
A simple package for displaying the current focus target path for an AppKit window.
- Press and hold
option-[
key to display the focus key path for the currently focussed window - Press and hold
option-]
key to display the focus key path from the currently focussed UI element.
Supports both Swift and Objective-C projects.
Demo
Click here to see a demo video of the focus overlay added to the wonderful 'ControlRoom' application.
There is also a very basic AppKit example applications in both Swift and Objective-C in the Demo
subfolder you can play with.
Simple setup
Define a global instance of AppKitFocusOverlay
in your app and access the instance within a method that gets called early in your app's lifecycle, such as applicationDidFinishLaunching
.
import AppKitFocusOverlay
let _globalFocusOverlay = AppKitFocusOverlay()
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Force the focus overlay instance to init.
_ = _globalFocusOverlay
...
}
Features
Custom hotkeys
You can define the hotkeys to use in the initializer of the instance. By default, these are option-[
and option-]
, but you can change them to f13
and f14
(for example) if you want.
import AppKitFocusOverlay
import HotKey // Available due to AppKitFocusOverlay dependency
let _globalFocusOverlay: AppKitFocusOverlay(
windowHotKey: HotKey(key: .f13, modifiers: []),
viewHotKey: HotKey(key: .f14, modifiers: [])
)
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Force the focus overlay instance to init.
_ = _globalFocusOverlay
...
}
Objective-C support
You can add AppKitFocusOverlay
to your Objective-C project easily.
@import AppKitFocusOverlay;
@interface AppDelegate ()
/// Define an instance of the focus overlay
@property (nonatomic, strong) AppKitFocusOverlay* focusOverlay;
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification*)aNotification {
/// Create the overlay and attach
AppKitFocusOverlay* focus = [[AppKitFocusOverlay alloc] init];
[self setFocusOverlay: focus];
}
@end
Note that if you need to customize the hotkeys for objective-c you'll need to fork this library and change the code in AppKitFocusOverlay.swift
, as the HotKey library is not exposed through Objective-C and as such the hotkey-setting initializers are not exposed to objc.
Screenshots
Thanks!
Uses HotKey to define and detect hot-key presses.
License
MIT. Use it for anything you want, just attribute my work if you do. Let me know if you do use it somewhere, I'd love to hear about it!
MIT License
Copyright (c) 2021 Darren Ford
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.