It's time to revisit how Spectacle serializes shortcuts. Currently shortcuts are serialized as NSData instances before being saved to disk through NSUserDefaults. Despite the simplicity of this approach it is often not flexible enough. Many folks want to easily export and import their custom shortcuts or even use the defaults command to change shortcuts.
To make everybody's lives a bit easier let's think of a friendlier way to serialize shortcuts and how to migrate them.
I'd love to see a YAML or JSON format which I could share between machines by soft linking to the rest of my dotfiles.
Just in case anyone lands here and is looking for a fix before anything gets improved: https://github.com/mathiasbynens/dotfiles/issues/507#issuecomment-93173783
For those how want to automate things, here is the script I am using https://github.com/MoOx/setup/blob/b4a14cebff65e564aa222907bb3372a4e0/preferences/Spectacle.backprefs
@eczarny Sublime text uses JSON! They seem to use a mix of named keys (alt, shift, etc) and actual letters (eg. k). It syncs really painlessly via symlink.
see: https://github.com/Xavdidtheshadow/dotfiles/blob/master/ST3/Packages/User/Default%20(OSX).sublime-keymap
Right now I'm working on a simple implementation of using JSON to store shortcuts. The format will be a simple array of shortcut objects. Each shortcut object contains the shortcut's name, the shortcut's code (an integer that maps to key code), and the shortcut's modifiers (an unsigned integer that maps to modifier flags).
Even this will be a big improvement. In the future I'd like to provide a friendlier mechanism similar to keymaps used by many text editors.
+1 on an improved interface for defining these. My vote would be to continue to have them stored using the defaults system.
Does there exist a consensus defining how to improve the way these are stored? Are there competing suggestions to consider? Is this being discussed anywhere other than this thread?
I arrived here in trying to automate my local setup. I ran into two issues doing this:
So, for example, I'd like to be able to run:
$ defaults write com.divisiblebyzero.Spectacle MoveToFullscreen -string 'ctrl+alt+enter'
to set a keybinding (regardless of whether the app is currently running on or has ever been run on my system). And I'd like to run
$ defaults read com.divisiblebyzero.Spectacle MoveToFullscreen
and see
ctrl+alt+enter
as the output.
On the topic of migrating existing users, I wonder if we should move to a new domain? com.divisiblebyzero.Spectacle2? I think it makes sense if we're introducing a non-backward compatible change. I like the current key names, so I'd like to keep them in tact.
Another way we could approach migrating is to introduce a single dictionary value that defines all the bindings. Using that approach, our interactions might look as follows:
$ defaults write com.divisiblebyzero.Spectacle Keybindings -dict MoveToFuullscreen -string 'ctrl-alt-enter' MoveToLeftHalf -string 'super+alt+left'
$ defaults read com.divisiblebyzero.Spectacle Keybindings
{
MoveToFuullscreen = "ctrl-alt-enter";
MoveToLeftHalf = "super+alt+left";
}
$ defaults write com.divisiblebyzero.Spectacle Keybindings -dict MoveToFullscreen -string 'ctrl-alt-enter' MoveToLeftHalf -string 'super+alt+left'
$ defaults read com.divisiblebyzero.Spectacle Keybindings
{
MoveToFullscreen = "ctrl-alt-enter";
MoveToLeftHalf = "super+alt+left";
}
$ defaults write com.divisiblebyzero.Spectacle Keybindings -dict-add MoveToCenter -string 'ctrl-alt-c'
$ defaults read com.divisiblebyzero.Spectacle Keybindings
{
MoveToCenter = "ctrl-alt-c";
MoveToFullscreen = "ctrl-alt-enter";
MoveToLeftHalf = "super+alt+left";
}
How do we solve the problem of writing defaults while the application may be running?
@eczarny is this something I can help out with? Is there anyone else you think we should bring into this conversation? Let me know what you think regarding the thoughts I shared above. – Thanks!
@ryanhanks thanks for your suggestions! Right now I'm actually storing shortcuts in a JSON file under ~/Library/Application Support/Spectacle. This feels like a better fit and this is already implemented on master. Check it out!
I like the idea of using the bindable keys that Sublime Text uses so I can spend some time working on that.
You'll notice too that Spectacle will try to migrate shortcuts from the app preferences plist file.
Spectacle now (on master) stores shortcuts as JSON with human readable key bindings. If folks are interested in trying it out let me know and I'll share a test build the the new functionality.
Awesome! What's the timeline for releasing that? Or do you want some pretty through testing first?
If it's a short wait, i'll just wait for the release. Otherwise, I'm happy to help test it
~DavidB
[davidbrownman.com]
c: 303.819.0850 (tel:303.819.0850)
On Sep 5, 2016, 12:57 PM -0700, Eric Czarny [email protected], wrote:
Spectacle now (on master) stories shortcuts as JSON with human readable key bindings. If folks are interested in trying it out let me know and I'll share a test build the the new functionality.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub (https://github.com/eczarny/spectacle/issues/424#issuecomment-244805137), or mute the thread (https://github.com/notifications/unsubscribe-auth/ABLMP0SlGsFWmBKk7MG00muJ2dOOrtYhks5qnHQ1gaJpZM4FrP4R).
@xavdid I plan to test these changes thoroughly so any help there would be appreciated. I'm hoping to ship 1.1 in a few weeks.
Sweet, i'm happy to switch over. What's the best way to distribute the beta build?
~DavidB
[davidbrownman.com]
c: 303.819.0850 (tel:303.819.0850)
On Sep 5, 2016, 1:02 PM -0700, Eric Czarny [email protected], wrote:
@xavdid (https://github.com/xavdid) I plan to test these changes thoroughly so any help there would be appreciated. I'm hoping to ship 1.1 in a few weeks.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub (https://github.com/eczarny/spectacle/issues/424#issuecomment-244805556), or mute the thread (https://github.com/notifications/unsubscribe-auth/ABLMP-GPTh2It3DwysJvdOLjCa3zdhNCks5qnHVNgaJpZM4FrP4R).
@xavdid I'll just add a comment here with a link to a 1.1a build. Should have one ready shortly.
Here's a 1.1a build from 80171cd019c46f46afded8714212816aba4bf8a3:
https://s3.amazonaws.com/spectacle/downloads/Spectacle+1.1a.zip
Spectacle should migrate any custom shortcuts to the new JSON storage, please let me know if that doesn't work as expected.
Here's an updated 1.1a build from f418da9:
https://s3.amazonaws.com/spectacle/downloads/Spectacle+1.1a.zip
@eczarny is the new json file stored in a certain place on the filesystem?
@xavdid yup! You can find it under ~/Library/Application Support/Spectacle.
Missed this one, awesome!
I'm wondering if it's possible / makes sense to add something like:
{
"Launch at Login" : true,
"Background Application" : true
},
For:

Or if you have other suggestions on automating this step?
Cheers!
Most helpful comment
@xavdid yup! You can find it under
~/Library/Application Support/Spectacle.