Skip to content

Instantly share code, notes, and snippets.

@jonomf
Created May 5, 2022 16:04
Show Gist options
  • Save jonomf/201badf429da48b9a28a5afd808ddd56 to your computer and use it in GitHub Desktop.
Save jonomf/201badf429da48b9a28a5afd808ddd56 to your computer and use it in GitHub Desktop.
Obsidian.md graph color syncing python script
import json
graphFile = open("../graph.json")
graphData = json.load(graphFile)
colorGroups = graphData['colorGroups']
print(f'colorGroups: {colorGroups}')
graphFile.close()
workspaceFile = open("../workspace")
workspaceData = json.load(workspaceFile)
print(f'workspaceData before: {workspaceData}')
def searchChildren(data):
if not data.get('children') is None:
for i in data.get('children'):
searchChildren(i)
if not data.get('state') is None:
if data['state']['type'] == "localgraph":
data['state']['state']['options']['colorGroups'] = colorGroups
searchChildren(workspaceData['main'])
print(f'workspaceData after: {workspaceData}')
workspaceFile.close()
with open("../workspace", 'w') as workspaceFile:
json.dump(workspaceData, workspaceFile, indent=2)
@jonomf
Copy link
Author

jonomf commented Mar 22, 2023

https://github.com/Xallt/sync-graph-settings is a plugin that solves this properly with a command, works great! I've switched to using the plugin over the script in this gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment