Skip to content

Automated Obsidian sync setup for Android using Git (SSH), Termux, and Tasker.

License

Notifications You must be signed in to change notification settings

toboil-features/obsidian-android-sync

 
 

Repository files navigation

Obsidian Android Sync

Easily sync your Obsidian vaults on Android using Git (SSH) + Termux, with automation and shortcuts using Tasker. It works by syncing a vault when it's opened and when it's closed.

Final-result

Above is an image of what it looks like, once complete with shortcuts to some optional utility functions. Each vault will have it's own icon. This allows syncing to be more efficient as without it, all vaults will sync each time in a specific order. Instead of just the vault that you open being synced immediately. If you only use one vault or don't mind the inefficiency of waiting for the vault that you just opened to be updated, then you can use the default Obsidian app icon. Also, all vaults are synced once a day (defaults to 4am).

To prevent conflicts, I recommend you add the following lines to your .gitignore file in all your vaults that you'll be syncing using Git. If you notice a plugin has a file which is often in conflict, you'll want to add that as well (remember to un-track it with git rm --cached <file>):

/.obsidian/workspace.json
/.obsidian/workspace-mobile.json
/.obsidian/plugins/obsidian-git/data.json
/conflict-files-obsidian-git.md

To stop conflicts from happening with your note files, you can create a .gitattributes file in the root of your vaults with the following content. It will basically always accept both changes for .md files.

*.md merge=union

Termux Setup

  1. Install Tasker from the Play Store.

  2. Install F-Droid.

  3. Install Termux, Termux:Tasker, and Termux:API apps from F-Droid (NOT from the Play Store).

    The next steps will mostly ask you to run commands in Termux.

  4. Run termux-setup-storage and give access to files.

  5. Run pkg update && pkg upgrade -y && pkg install -y git openssh termux-api to install packages. Press Enter any time it pauses with a question.

  6. Run mkdir -p /storage/emulated/0/repos/Obsidian to create the directories used for repositories.

  7. Run git clone https://github.com/DovieW/obsidian-android-sync.git ~/storage/shared/repos/obsidian-android-sync to clone this repo into the repos directory.

    Be aware that the next step will set safe.directory to '*'.

  8. Run the setup script: cp "/storage/emulated/0/repos/obsidian-android-sync/setup" ~/ && chmod +x "$HOME/setup" && source "$HOME/setup". Type yes and hit Enter if prompted.

  9. The above command copied an SSH public key to your clipboard (or was displayed to the screen), paste this into your Git host's SSH key authentication setting (eg Github). If you want to copy the SSH key again, run the setup script again by simply running setup. The long verison of the setup command (above) is not needed anymore.

  10. In Termux, you should now be in the Obsidian directory (verify with pwd) where you should now clone your Obsidian vaults. Try not to put any special characters (that are recognized by bash) in your vault name (eg an ampersand or exclamation point etc), if I remember correctly, it gave Tasker some issues, but you can probably get around that issue if you try. I don't know how spaces will behave.

At this point, you can run sync to sync all the vaults in the /storage/emulated/0/repos/Obsidian folder.

Tasker Setup

  1. Enable the Termux permission in the settings for the Tasker app.
  2. Open the Obsidian app and add your vaults from the repos/Obsidian folder.
  3. If you're using the Obsidian Git plugin, you should disable it for this device. You can do this in the plugin settings.
  4. Import the "Tasker project" into Tasker. Once you import it, I recommend you rearrange the tasks based on this image for simplicity (to rearrange tasks, hold on a task, then drag). You can import the project in 2 ways. You can use this TaskerNet link, or you can import (image) the .xml file from this repository. Once it's imported, there will be some prompts, I think one for giving Tasker "Usage Access" and one to enable all profiles. Accept all.
  5. Vault launch icons - There are 2 example tasks (Vault1 and Vault2). Rename the task to the name of your vault (you can name it anything). Then in the task, you'll see a "Variable Set" action, change the value to the name of the folder which contains the repository for that vault.
  6. Give Termux the "Display over other apps" permission.
  7. Add the Vault launch icons as Tasker widgets (use the widget type that allows you to add them to folders) to the home screen. Also, add the 3 helper tasks as widgets (as needed):
    1. Sync Vaults - syncs all vaults
    2. Vaults Status - outputs the git fetch && git status of each vault
    3. Sync Log - outputs the sync log.

All vaults will sync at 4am every day using a Tasker profile.

Notes

  • You should get a notification if a sync fails. This requires AutoNotification from the PlayStore. To disable this, disable the Sync Error Notification profile.
  • The individual vault icons to open specific vaults can be a bit slow. I've tried different ways to open a vault. Faster ways had one of two problems. Either it would open the vault correctly, but then if you left the app, it would not appear in the recents list. Or, it would load the app, load the last vault used, then load the vault you wanted which ends up being slower then the current method. You can find almost all the methods I tried in the Open Vault task (they are disabled).
  • If you prefer, you can have a popup menu (a scene or list dialog for example), to combine all the actions or vaults into one icon on your home screen.
  • If this repository has new commits that you want, running the setup command should pull them down. After which, you may be prompted to run a command to update the setup script itself, if it was updated.

About

Automated Obsidian sync setup for Android using Git (SSH), Termux, and Tasker.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 100.0%