Spectacle: Shortcuts.json order changes every time Spectacle is launched

Created on 17 Jan 2017  Â·  4Comments  Â·  Source: eczarny/spectacle

It seems that the order of the shortcuts in Shortcuts.json changes every time the application is launched. This means that if you check the config file into Git, new changes are generated every time you start Spectacle.

I'm using Spectacle 1.2 (672) on OSX 10.12.2.

Steps to reproduce:

  1. Open Spectacle preferences
  2. Click "Restore Defaults"
  3. cp ~/Library/Application\ Support/Spectacle/Shortcuts.json ~/Desktop/Shortcuts.json.1
  4. Quit Spectacle and re-open it
  5. cp ~/Library/Application\ Support/Spectacle/Shortcuts.json ~/Desktop/Shortcuts.json.2
  6. diff ~/Desktop/Shortcuts.json.1 ~/Desktop/Shortcuts.json.2 -- example output:
11,12c11,12
<     "shortcut_key_binding" : "ctrl+shift+cmd+right",
<     "shortcut_name" : "MoveToLowerRight"
---
>     "shortcut_key_binding" : "ctrl+alt+left",
>     "shortcut_name" : "MoveToPreviousThird"
67,68c67,68
<     "shortcut_key_binding" : "ctrl+cmd+left",
<     "shortcut_name" : "MoveToUpperLeft"
---
>     "shortcut_key_binding" : "ctrl+shift+cmd+right",
>     "shortcut_name" : "MoveToLowerRight"
71,72c71,72
<     "shortcut_key_binding" : "ctrl+alt+left",
<     "shortcut_name" : "MoveToPreviousThird"
---
>     "shortcut_key_binding" : "ctrl+cmd+left",
>     "shortcut_name" : "MoveToUpperLeft"

As you can see, the order of the shortcuts changed, but the bindings are identical. If you repeat this process multiple times, you will continue to see new orderings being written to Shortcuts.json.

defect ★

Most helpful comment

Interesting issue! I'll spend some time investigating. I can totally see how this could be an issue if you keep your configuration files in source control. Thanks for reporting.

All 4 comments

Interesting issue! I'll spend some time investigating. I can totally see how this could be an issue if you keep your configuration files in source control. Thanks for reporting.

Hello. Any timeline for the fix?

Okay so on initial inspection it looks like the issue is that when the shortcut array is written to JSON here it isn't sorted:

https://github.com/eczarny/spectacle/blob/7fb5f1cbe49f178dffafaef84c199e0b8f084784/Spectacle/Sources/SpectacleShortcutJSONStorage.m#L78-L88

I guess the easiest way to fix would be to sort the NSMutableArray<NSDictionary *> *jsonArray = [NSMutableArray new]; by key after filling it. This SO answer might be helpful.

@gibfahn FYI this issue is fixed in #810 It's waiting to be merged.

Was this page helpful?
0 / 5 - 0 ratings