<?xml version="1.0" encoding="utf-8"?><rss version="2.0"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:wfw="http://wellformedweb.org/CommentAPI/"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:atom="http://www.w3.org/2005/Atom"
    xmlns:media="http://search.yahoo.com/mrss/"
    xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
    xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
>
<channel>
  <title>Srijan Choudhary, all posts tagged: android</title>
  <link>https://srijan.ch/feed/all/tag:android</link>
  <lastBuildDate>Mon, 13 Jan 2025 18:20:00 +0000</lastBuildDate>
  <image>
    <url>https://srijan.ch/assets/favicon/favicon-32x32.png</url>
    <title>Srijan Choudhary, all posts tagged: android</title>
    <link>https://srijan.ch/feed/all/tag:android</link>
  </image>
  <sy:updatePeriod>daily</sy:updatePeriod>
  <sy:updateFrequency>1</sy:updateFrequency>
  <generator>Kirby</generator>
  <atom:link href="https://srijan.ch/feed/all.xml/tag:android" rel="self" type="application/rss+xml" />
  <description>Srijan Choudhary&#039;s Articles and Notes Feed for tag: android</description>
  <item>
    <title>Triggering Orgzly sync on Android when Org file changes</title>
    <description><![CDATA[Event based orgzly sync using tasker to prevent conflicts]]></description>
    <link>https://srijan.ch/triggering-orgzly-sync-on-android-when-org-file-changes</link>
    <guid isPermaLink="false">tag:srijan.ch:/triggering-orgzly-sync-on-android-when-org-file-changes</guid>
    <category><![CDATA[emacs]]></category>
    <category><![CDATA[orgmode]]></category>
    <category><![CDATA[android]]></category>
    <category><![CDATA[tasker]]></category>
    <dc:creator>Srijan Choudhary</dc:creator>
    <pubDate>Mon, 13 Jan 2025 18:20:00 +0000</pubDate>
    <content:encoded><![CDATA[<h3>Introduction</h3>
<p>To use my org GTD system on the go, I use the excellent <a href="https://www.orgzlyrevived.com/">Orgzly Revived</a> mobile app for Android. To sync the org files between my laptop and my phone, I use <a href="https://syncthing.net/">syncthing</a> (specifically, the <a href="https://github.com/Catfriend1/syncthing-android">Syncthing Android Fork by Catfriend1</a>).</p>
<p>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.</p>
<h3>Sync Issues</h3>
<p>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.</p>
<p>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.</p>
<p>But, the Orgzly app <a href="https://github.com/orgzly-revived/documentation/blob/master/android/public-receiver.org">supports intents</a> that can be used from Tasker, Automate, etc to trigger an event-based sync.</p>
<h3>Tasker Profile</h3>
<p>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: <a href="https://taskernet.com/?public&amp;tags=orgzly&amp;time=AllTime">https://taskernet.com/?public&amp;tags=orgzly&amp;time=AllTime</a> called "Run Orgzly Sync When Org Files Change".</p>
<p>Here's the basic flow of the profile:</p>
<pre><code class="language-less">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 &amp; %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</code></pre>
<h3>How it works</h3>
<ol>
<li>When importing this profile, it will ask for your org folder in the local Android filesystem.</li>
<li>Once selected and the profile is activated, it will start monitoring this folder for inotify events.</li>
<li>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.</li>
<li>Then, it checks if the affected file is an org file (ending in <code>.org</code>) 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.</li>
<li>If yes, then Orgzly sync is triggered using an intent.</li>
</ol>
<p>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.</p>
<h3>Limitations</h3>
<ol>
<li>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.</li>
<li>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.</li>
</ol>
<h3>Alternatives</h3>
<ol>
<li>Orgzly Revived has a git sync backend in beta. This might work better with auto-commit &amp; push.</li>
<li>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.</li>
</ol>]]></content:encoded>
    <comments>https://srijan.ch/triggering-orgzly-sync-on-android-when-org-file-changes#comments</comments>
    <slash:comments>21</slash:comments>
  </item></channel>
</rss>
