Kentzo / ShortcutRecorder

The best control to record shortcuts on macOS, written in ObjC with Swift in mind
Other
575 stars 115 forks source link
cocoa macos shortcut ui

CC BY 4.0 macOS 10.11 Mac App Store Approved

CocoaPods Compatible Carthage Compatible SPM Compatible

Coverage Build Status

ShortcutRecorder

Showcase

The best control to record shortcuts on macOS

What is inside

The framework comes with:

In Swift:

import ShortcutRecorder

let defaults = NSUserDefaultsController.shared
let keyPath = "values.shortcut"
let options = [NSBindingOption.valueTransformerName: .keyedUnarchiveFromDataTransformerName]

let beepAction = ShortcutAction(keyPath: keyPath, of: defaults) { _ in
    NSSound.beep()
    return true
}
GlobalShortcutMonitor.shared.addAction(beepAction, forKeyEvent: .down)

let recorder = RecorderControl()
recorder.bind(.value, to: defaults, withKeyPath: keyPath, options: options)

recorder.objectValue = Shortcut(keyEquivalent: "⇧⌘A")

In Objective-C:

#import <ShortcutRecorder/ShortcutRecorder.h>

NSUserDefaultsController *defaults = NSUserDefaultsController.sharedUserDefaultsController;
NSString *keyPath = @"values.shortcut";
NSDictionary *options = @{NSValueTransformerNameBindingOption: NSKeyedUnarchiveFromDataTransformerName};

SRShortcutAction *beepAction = [SRShortcutAction shortcutActionWithKeyPath:keyPath
                                                                  ofObject:defaults
                                                             actionHandler:^BOOL(SRShortcutAction *anAction) {
    NSBeep();
    return YES;
}];
[[SRGlobalShortcutMonitor sharedMonitor] addAction:beepAction forKeyEvent:SRKeyEventTypeDown];

SRRecorderControl *recorder = [SRRecorderControl new];
[recorder bind:NSValueBinding toObject:defaults withKeyPath:keyPath options:options];

recorder.objectValue = [SRShortcut shortcutWithKeyEquivalent:@"⇧⌘A"];

Integration

The framework supports module maps, explicit linking is not required: simply import ShortcutRecorder / #import <ShortcutRecorder/ShortcutRecorder.h>

Swift Package Manager

.package(url: "git://github.com/Kentzo/ShortcutRecorder.git", from: "3.4.0")

CocoaPods

pod 'ShortcutRecorder', '~> 3.4.0'

Carthage

github "Kentzo/ShortcutRecorder" ~> 3.4.0

Prebuilt frameworks are available via GitHub releases.

Git Submodule

git submodule add git://github.com/Kentzo/ShortcutRecorder.git

Then drag'n'drop into Xcode workspace of your project.

Next Steps

Questions

Still have questions? Create an issue.

Paid Support

Paid support is available for custom alterations, help with integration and general advice regarding development for Apple's platforms.