Triggering Orgzly sync on Android when Org file changes

Srijan Choudhary Srijan Choudhary
- 2 min read

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

  1. When importing this profile, it will ask for your org folder in the local Android filesystem.
  2. Once selected and the profile is activated, it will start monitoring this folder for inotify events.
  3. 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.
  4. 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.
  5. 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

  1. 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.
  2. 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

  1. Orgzly Revived has a git sync backend in beta. This might work better with auto-commit & push.
  2. 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

  • Nick Anderson

    @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.

    Reply
  • y1okqw711kj0

    Bookmark: srijan.ch/triggering-org...

    Reply
  • Blytheway

    This is how I find out Syncthing android is being deprecated

    Reply
    • Srijan Choudhary
      Srijan Choudhary

      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.

      Reply