Created
May 5, 2022 16:04
-
-
Save jonomf/201badf429da48b9a28a5afd808ddd56 to your computer and use it in GitHub Desktop.
Obsidian.md graph color syncing python script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
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
This script copies the Obsidian main graph groups and colors to any open local graphs.
Note this script is brittle:
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!