I use Obsidian git on PC, and this workaround (since the plugin doesn't support mobile) to seamlessly* sync my notes to and from my phone. Using these instructions you create an automation for pulling every time you open Obsidian, and pushing every time you close it.
* you can still get merge conflicts...
Merge conflicts are not handled and will prevent pushing and pulling. Basically just make sure you only work on your repository from one device at a time.
- Install Tasker.
- Install Termux.
- Install Termux tasker plugin.
- Open Termux and write
termux-setup-storage
, give it permissions. - Generate a new ssh key and add it to your Github profile.
pkg install git
.cd ~/storage/shared
and clone / create a repository in a folder of your choice. I use~/storage/shared/Repos/Obsidian
.mkdir ~/.termux/tasker/
andcd ~/.termux/tasker/
.chmod 700 -R /data/data/com.termux/files/home/.termux
- Create the scripts below inside the folder from step 7.
You need two scripts
pull.sh
andbackup.sh
. I added another script -reset.sh
, which I use for resetting in case of merge conflict.
#!/data/data/com.termux/files/usr/bin/bash
git pull
exit 0
#!/data/data/com.termux/files/usr/bin/bash
git add .
git commit -m "mobile backup"
git push
exit 0
#!/data/data/com.termux/files/usr/bin/bash
git reset --hard
exit 0
If you want your tasks to ask you for permission and / or print output messages, then you can build your tasks like this:
1. Pick input dialog YesOrNo "Do this?" (this = pull / push / reset).
2. If %input ~ yes
3. Termux action (the ones defined below)
4. If (%stdout NEQ \%stdout)
5. Flash Text %stdout
6. End if
7. If (%stderr NEQ \%stderr)
8. Flash Text %stderr
9. End if
10. End if
For every task create the following Termux action
- path:
script.sh
(i.e.backup.sh
,pull.sh
orreset.sh
).
- arguments:
- None
- working directory path:
~/storage/shared/Repos/Obsidian
(or whatever you use).
- execute in a terminal session:
- unchecked
When you have your tasks ready you can create your profile:
- Choose application -> Obsidian.
- Choose your pull task.
- Long press the green arrow next to your pull task, and choose "add exit task".
- Choose your backup task.
I only use the reset task via a shortcut, as automating it is too dangerous and it is not required very often.