After using Obsidian for a week, I fell in love with it. Previously, I had been using OneNote to take and organize my notes in folders. However, I missed the ability to quickly format my notes using Markdown, which I had grown accustomed to using with Rmarkdown and Jupyter. The versatility to format text, add images, and use Mathjax for technical notes was something that OneNote couldn’t provide.
One thing I did like about OneNote was the cloud synchronization feature. However, this awesome article by Bryan Jenks opened up the possibility of keeping my notes synced with GitHub, which is amazing. One of the best features of Markdown is the ability to track changes, since it’s plain text and much different from Word files. Here are the basic steps to set this up:
- Create an empty repository
- Add the following lines to the ignore file: .obsidian/cache .trash/ .DS_store
- Do the initial commit
- Run a script to automate the commits and push. Since my computer runs on Windows, I prefer using a PowerShell script. To do this, you need to install posh-git and write the following code for Windows:
$vault_path="YOUR ABSOLUTE VAULT PATH"
cd "$vault_path"
$CHANGES_EXIST="$(git status --porcelain | wc -l)"
if($CHANGES_EXIST -eq 0){exit;}
git pull
git add .
git commit -q -m "Last Sync: $(Get-Date -format 'u')"
git push -q
For Windows, save the script as obsidian_script.ps1. For Mac, use the following code:
#!/usr/bin/env sh
vault_path="YOUR ABSOLUTE VAULT PATH"
cd "$vault_path"
git pull
CHANGES_EXIST="$(git status --porcelain | wc -l)"
if [ "$CHANGES_EXIST" -eq 0 ]; then
exit 0
fi
git pull
git add .
git commit -q -m "Last Sync: $(date +"%Y-%m-%d %H:%M:%S")"
git push -q
-
To run the script using cron on Windows:
Access the task scheduler by pressing Win+R and typing “taskschd.msc” Click “Create Basic Task” Set the trigger for when you want the script to run Enter the path of the shell script Click “Finish” and the task is set up.
On Mac, you can use the crontab
command to schedule the script to run at specific intervals.
For example, to run the script every hour, you can use the following command:
0 * * * * /path/to/obsidian_script.sh
Bonus step
To create a shortcut to run the script using AutoHotkey on Windows:
- Create a file called obsidian.ahk using the provided script.
- Run the obsidian.ahk file to create the shortcut. The shortcut will be Ctrl+Shift+o.
- To set the ahk file to start with Windows, you can either add it to the task scheduler or add a shortcut for the ahk file in the startup folder. To access the startup folder, press Win+R and type “shell:startup”.
- The code for the obsidian.ahk file is provided below:
^+o::
run powershell.exe -WindowStyle hidden -File "YOUR obsidian.ps1 PATH"
return
To create a shortcut to run the script on Mac using Automator:
- Open Automator and select “File” then “New” and choose “Quick Action”.
- Search for “Run Shell Script” and in the “Shell” dropdown, select “/bin/sh”.
- Add the following command:
`sh /usr/local/bin/zk_sync`
- Name the action and save it.
- Go to “System Preferences” then “Keyboard” and select “Shortcuts”.
- Under “Services”, you should find your script. Assign a key combination to it.