Skip to content

Instantly share code, notes, and snippets.

@jonomf
Created May 5, 2022 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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 May 5, 2022

This script copies the Obsidian main graph groups and colors to any open local graphs.

Note this script is brittle:

  • As-is, it has to be one folder deeper into your .obsidian directory
  • Obsidian must be closed when this runs

I'm interested in converting it to an actual Obs plugin, and am tracking a feature request for the same -- hoping to find an officially supported way to do this!

@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