##Macro Idea: Get KMMacros File as JSON (Human-readable text) v0.1
Get KMMacros File as JSON v0.1.kmmacros (9.4 KB)
I just know that this is a really useful idea, I just can't quite figure out how. I'm hoping some of you might be able to figure out its usefulness.
This code converts a .kmmacros file to a JSON string. The result is much more easily read than a plist file.
NOTE: It doesn't have to be a .kmmacros file - it could get the actual source from the KME. I'm just using a .kmmacros file for testing.
There's actually two outputs:
-
The unfiltered result of converting the plist to JSON.
-
A filtered and restructured version - just the start of an idea of how we might be able to make the result even more useful.
Here's some of my thoughts:
-
I can't help but think this would be useful for something like searching for things, possibly even doing find-and-replace actions. So far, it appears I can convert back to a .kmmacros file just fine.
-
I like to store versions of some of my macros in Git. But comparing them to see what changed is really hard. So I'm thinking that a filtered-down and possibly re-structured version of a JSON string might be a better way to store the macros, at least for comparison's sake.
###Unaltered output:
[
{
"Macros": [
{
"UID": "C31D958F-F99B-42F8-B4D1-FE14F304E53D",
"Actions": [
{
"Variable": "gkajKmmacrosPath",
"MacroActionType": "SetVariableToText",
"Text": "~/Documents/test.kmmacros"
},
{
"TrimResults": true,
"MacroActionType": "ExecuteJavaScriptForAutomation",
"TimeOutAbortsMacro": true,
"Text": "",
"Path": "",
"TrimResultsNew": true,
"IncludeStdErr": true,
"DisplayKind": "Window",
"UseText": true
}
],
"CreationDate": 493203896.805307,
"ModificationDate": 493204009.599146,
"Triggers": [],
"Name": "Get KMMacros File as JSON"
}
],
"UID": "C913CB41-43FF-4375-99C4-EE925739BE7D",
"Targeting": {
"Targeting": "Included",
"TargetingApps": [
{
"NewFile": "/Applications/Keyboard Maestro.app",
"BundleIdentifier": "com.stairways.keyboardmaestro.editor",
"Name": "Keyboard Maestro"
}
]
},
"Activate": "Normal",
"CreationDate": 490752742.264982,
"ToggleMacroUID": "CF50116E-47B9-4929-A637-1B4733232DD3",
"Name": "KM"
}
]
###Modified Output:
[
{
"name": "KM",
"uid": "C913CB41-43FF-4375-99C4-EE925739BE7D",
"macros": [
{
"name": "Get KMMacros File as JSON",
"uid": "C31D958F-F99B-42F8-B4D1-FE14F304E53D",
"actions": [
{
"name": "SetVariableToText",
"content": {
"Variable": "gkajKmmacrosPath",
"MacroActionType": "SetVariableToText",
"Text": "~/Documents/test.kmmacros"
}
},
{
"name": "ExecuteJavaScriptForAutomation",
"content": {
"TrimResults": true,
"MacroActionType": "ExecuteJavaScriptForAutomation",
"TimeOutAbortsMacro": true,
"Text": "",
"Path": "",
"TrimResultsNew": true,
"IncludeStdErr": true,
"DisplayKind": "Window",
"UseText": true
}
}
]
}
]
}
]
Like I said, by gut says this is useful. I'm just not sure how.
Ideas?