Triggering Orgzly sync on Android when Org file changes
Introduction
To use my org GTD system on the go, I use the excellent Orgzly Revived mobile app for Android. To sync the org files between my laptop and my phone, I use syncthing (specifically, the Syncthing Android Fork by Catfriend1).
This allows me to quickly capture things from my phone, get reminder notifications of time-sensitive tasks, and mark tasks complete from my phone. The widgets are also useful for quickly looking at some contexts like errands or calls.
Sync Issues
However, Orgzly works by contructing a copy of the contents in it's own database and synchronizing it against the files periodically or when some action is taken in the app. Right now, it does not support synchronizing the data when the file changes.
For me, this has sometimes lead to a conflict between the Orgzly database and the actual files in the org folder. This only happens if the org file is edited on my laptop and something is also edited in the Orgzly app before syncing.
But, the Orgzly app supports intents that can be used from Tasker, Automate, etc to trigger an event-based sync.
Tasker Profile
So, I created a tasker profile to do this. It was surprisingly easy (I've used tasker before, though not too much). It can be found here: https://taskernet.com/?public&tags=orgzly&time=AllTime called "Run Orgzly Sync When Org Files Change".
Here's the basic flow of the profile:
Profile: Run Orgzly Sync When Org Files Change
Settings: Notification: no
Variables: [ %orgfolder:has value ]
Event: File Modified [ File:%orgfolder Event:* ]
Enter Task: Orgzly Sync
Settings: Run Both Together
A1: If [ %evtprm1 ~ *.org & %evtprm2 ~ ClosedWrite/MovedTo ]
A2: Send Intent [
Action: com.orgzly.intent.action.SYNC_START
Cat: None
Package: com.orgzlyrevived
Class: com.orgzly.android.ActionReceiver
Target: Broadcast Receiver ]
A3: End If
How it works
- When importing this profile, it will ask for your org folder in the local Android filesystem.
- Once selected and the profile is activated, it will start monitoring this folder for inotify events.
- When any file is modified (or created or moved to/from the folder or deleted), this profile is triggered. It received the parameters: full path of the affected file, and the actual event.
- Then, it checks if the affected file is an org file (ending in
.org
) AND if the event is one of ClosedWrite or MovedTo. I filtered to these events because they are usually the last event received for an edit. - If yes, then Orgzly sync is triggered using an intent.
I've been using this for the last several months, and it works well as long as both devices are online when making edits. Conflicts can still happen if, for example, I make some edits on my laptop and subsequently on my phone but the phone is not online or the syncthing app is not running due to data saver or battery saver active. In those cases, eventually syncthing creates a conflicted file that I can manually resolve.
Limitations
- It does not support recursive files inside the folder. Tasker right now does not support recursively watching a folder, but if it's added this can be a good edition; specially because Orgzly Revived supports that.
- Since this watches the files in the folder, it also triggers a sync if Orgzly app was used to change the file. Not sure if this can be filtered somehow. Maybe based on foreground app? But it seems flakey.
Alternatives
- Orgzly Revived has a git sync backend in beta. This might work better with auto-commit & push.
- Using Emacs on Android instead of Orgzly is also an option, but I felt it did not work very well without an external keyboard. Also, it does not have widgets.
Interactions
π 4 likes
π 3 reposts
@srijan The last time I tried something like this I ended up with hourly syncthing conflicts!
@devalot Even without this, I did not have lots of conflicts, but enough that I decided to optimize it.
Make sure Auto-sync is turned on in Orgzly settings if you decide to try again.
@srijan I don't know what my problem is with syncthing. I only edit files on a single machine at a time, and I manually start syncthing on my phone. Even then I get sync conflicts, but only ever with org files. Weird.
@devalot @srijan when i had that i needed to force utf8 encoding in Orgzly.
@nickanderson @srijan Thanks for the tip.
@srijan i do something very similar, but i am a bit more aggressive. I trigger sync on screen wake. This helps the widget be up to date soon enough after grabbing phone to be useful.
@nickanderson Yeah, screen wake trigger can also be a good option, and might actually have less battery impact based on how frequently the org files are updated vs phone is unlocked.
Bookmark: srijan.ch/triggering-org...
This is how I find out Syncthing android is being deprecated
I had been using the Catfriend1 fork even before the official app was deprecated. It had several features that were not there in the official app and was under active development.