<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Tasker on foosel.net</title><link>https://foosel.net/tags/tasker/</link><description>Recent content in Tasker on foosel.net</description><generator>Hugo</generator><language>en-us</language><copyright>Gina Häußge (foosel)</copyright><lastBuildDate>Sat, 21 Jan 2023 00:00:00 +0000</lastBuildDate><atom:link href="https://foosel.net/tags/tasker/feed.xml" rel="self" type="application/rss+xml"/><item><title>How to open a file from Tasker in Markor</title><link>https://foosel.net/til/how-to-open-a-file-from-tasker-in-markor/</link><pubDate>Sat, 21 Jan 2023 00:00:00 +0000</pubDate><guid>https://foosel.net/til/how-to-open-a-file-from-tasker-in-markor/</guid><description>&lt;p&gt;In order to open a file from Tasker in Markor (e.g. to edit a &lt;a href="https://foosel.net/blog/2023-01-21-hugo-meet-android/"&gt;newly created blog post&lt;/a&gt;), create a &amp;ldquo;Send Intent&amp;rdquo; step with:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Action: &lt;code&gt;android.intent.action.SEND&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Cat: &lt;code&gt;None&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Mime Type: &lt;code&gt;text/plain&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Data: &lt;code&gt;content://net.dinglisch.android.taskerm.fileprovider/external_files/path/to/the/file&lt;/code&gt; (be sure to replace &lt;code&gt;/path/to/the/file&lt;/code&gt; with the absolute path to the file you want to open)&lt;/li&gt;
&lt;li&gt;Package: &lt;code&gt;net.gsantner.markor&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Class: &lt;code&gt;net.gsantner.markor.activity.DocumentActivity&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="https://www.reddit.com/r/tasker/comments/xbspjr/send_intent_to_markor/"&gt;Source&lt;/a&gt;&lt;/p&gt;</description><content:encoded><![CDATA[<p>In order to open a file from Tasker in Markor (e.g. to edit a <a href="/blog/2023-01-21-hugo-meet-android/">newly created blog post</a>), create a &ldquo;Send Intent&rdquo; step with:</p>
<ul>
<li>Action: <code>android.intent.action.SEND</code></li>
<li>Cat: <code>None</code></li>
<li>Mime Type: <code>text/plain</code></li>
<li>Data: <code>content://net.dinglisch.android.taskerm.fileprovider/external_files/path/to/the/file</code> (be sure to replace <code>/path/to/the/file</code> with the absolute path to the file you want to open)</li>
<li>Package: <code>net.gsantner.markor</code></li>
<li>Class: <code>net.gsantner.markor.activity.DocumentActivity</code></li>
</ul>
<p><a href="https://www.reddit.com/r/tasker/comments/xbspjr/send_intent_to_markor/">Source</a></p>
]]></content:encoded></item><item><title>Hugo, meet Android</title><link>https://foosel.net/blog/2023-01-21-hugo-meet-android/</link><pubDate>Sat, 21 Jan 2023 00:00:00 +0000</pubDate><guid>https://foosel.net/blog/2023-01-21-hugo-meet-android/</guid><description>Setting up a mobile blogging workflow</description><content:encoded><![CDATA[<p>One thing that kept me from blogging more so far was the difficulty in working on posts on my phone. So after switching this blog over to Hugo I decided to see if I couldn&rsquo;t improve on this situation.</p>
<p>I needed a solution that would allow me to</p>
<ol>
<li>Checkout my page&rsquo;s git repository from GitHub</li>
<li>Quickly create a new post, consisting of a new folder inside <code>content/blog</code> matching my chosen <code>&lt;year&gt;-&lt;month&gt;-&lt;day&gt;-&lt;title slug&gt;/index.md</code> folder structure, based on just a title</li>
<li>Allow me to edit the post, preferably in a text editor focused on Markdown (and ideally allow me to preview the post as well)</li>
<li>Optional: Run the Hugo build on my phone as well for final checks</li>
<li>Finally, commit the new post and push it so that my GitHub Action workflow can take care of the rest</li>
</ol>
<p>I started hunting for options, and I&rsquo;m happy to report that for now I seem to have found a - quite geeky - solution that involves the use of <a href="https://termux.dev/en">Termux</a> (Linux terminal environment for Android), <a href="https://gsantner.net/project/markor.html">Markor</a> (Markdown editor) and <a href="https://tasker.joaoapps.com/">Tasker</a> (Automation tool)<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup>.</p>
<p>I installed Termux, Termux:Tasker, Termux:Widget and Markor via <a href="https://f-droid.org/">F-Droid</a> - the versions available on Google Play are outdated and no longer supported. I already had Tasker installed, but I made sure to give it the additional permission to send commands to Termux. For Termux, I also made sure to allow it to draw over other apps.</p>
<p>I then fired up Termux and took care of storage access and some packages first:</p>
<pre tabindex="0"><code>termux-setup-storage
pkg upgrade
pkg install git gh hugo iconv vim
</code></pre><p>Markor&rsquo;s default folder is located at <code>Documents/markor</code> and so this is where I decided to checkout my page&rsquo;s repository to. I also made sure to set some config settings needed for stuff to work<sup id="fnref:2"><a href="#fn:2" class="footnote-ref" role="doc-noteref">2</a></sup>:</p>
<pre tabindex="0"><code>gh auth login
cd storage/shared/Documents/markor
git clone https://github.com/foosel/foosel.github.io
git config --global --add safe.directory /storage/emulated/0/Documents/markor/foosel.github.io
git config --global user.email &#34;you@example.com&#34;
git config --global user.name &#34;Your Name&#34;
</code></pre><p>Next I took care of some helper scripts for Termux:Widget and Tasker. I first created some folders:</p>
<pre tabindex="0"><code>mkdir -p ~/.shortcuts
chmod 700 -R ~/.shortcuts
mkdir -p ~/.termux/tasker
chmod 700 -R ~/.termux/tasker
</code></pre><p>Then I added some helper scripts to them:</p>
<p><code>~/.shortcuts/pull_blog</code></p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e">#!/bin/sh
</span></span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>cd ~/storage/shared/Documents/markor/foosel.github.io
</span></span><span style="display:flex;"><span>git pull
</span></span></code></pre></div><p><code>~/.shortcuts/push_blog</code></p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e">#!/bin/sh
</span></span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>cd ~/storage/shared/Documents/markor/foosel.github.io
</span></span><span style="display:flex;"><span>git push
</span></span></code></pre></div><p><code>~/.termux/tasker/serve_blog</code></p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e">#!/bin/sh
</span></span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>cd ~/storage/shared/Documents/markor/foosel.github.io
</span></span><span style="display:flex;"><span>hugo server -D -F --noBuildLock
</span></span></code></pre></div><p><code>~/.termux/tasker/new_blog_post</code></p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e">#!/bin/bash
</span></span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>checkout<span style="color:#f92672">=</span>~/storage/shared/Documents/markor/foosel.github.io
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>slugify <span style="color:#f92672">()</span> <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>     echo <span style="color:#e6db74">&#34;</span>$1<span style="color:#e6db74">&#34;</span> | iconv -t ascii//TRANSLIT | sed -r s/<span style="color:#f92672">[</span>~<span style="color:#ae81ff">\^</span><span style="color:#f92672">]</span>+//g | sed -r s/<span style="color:#f92672">[</span>^a-zA-Z0-9<span style="color:#f92672">]</span>+/-/g | sed -r s/^-+<span style="color:#ae81ff">\|</span>-+$//g | tr A-Z a-z
</span></span><span style="display:flex;"><span><span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>title<span style="color:#f92672">=</span>$1
</span></span><span style="display:flex;"><span>date<span style="color:#f92672">=</span><span style="color:#66d9ef">$(</span>date +%Y-%m-%d<span style="color:#66d9ef">)</span>
</span></span><span style="display:flex;"><span>slug<span style="color:#f92672">=</span><span style="color:#66d9ef">$(</span>slugify <span style="color:#e6db74">&#34;</span>$title<span style="color:#e6db74">&#34;</span><span style="color:#66d9ef">)</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>cd $checkout
</span></span><span style="display:flex;"><span>mkdir -p content/blog/$date-$slug
</span></span><span style="display:flex;"><span>cat &gt; content/blog/$date-$slug/index.md <span style="color:#e6db74">&lt;&lt;EOF
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">---
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">title: &#34;$title&#34;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">date: $date
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">draft: true
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">---
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">EOF</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>echo $date-$slug/index.md
</span></span></code></pre></div><p><code>~/.termux/tasker/commit_blog</code></p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e">#!/bin/sh
</span></span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>message<span style="color:#f92672">=</span>$1
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>cd ~/storage/shared/Documents/markor/foosel.github.io
</span></span><span style="display:flex;"><span>git add .
</span></span><span style="display:flex;"><span>git commit -m <span style="color:#e6db74">&#34;</span>$message<span style="color:#e6db74">&#34;</span>
</span></span></code></pre></div><p><code>pull_blog</code> and <code>push_blog</code> take care of git synchronization.</p>
<p><code>serve_blog</code> runs Hugo with draft and future posts visible. The page can be viewed in the browser on the phone at <code>http://localhost:1313</code>.</p>
<p><code>new_blog_post</code> takes a post title as its first argument and from that creates the aforementioned folder structure within the <code>content/blog</code> folder, including a prefilled <code>index.md</code>.<sup id="fnref:3"><a href="#fn:3" class="footnote-ref" role="doc-noteref">3</a></sup></p>
<p>And finally <code>commit_blog</code> takes a commit message as its first argument, stages all changes in the checkout and commits them with the supplied message.</p>
<p>Next, I created Termux:Widget widgets on my desktop for <code>pull_blog</code>, <code>push_blog</code> and <code>run_hugo</code>.</p>
<p>Then I opened Tasker and created two new tasks:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-plain" data-lang="plain"><span style="display:flex;"><span>    Task: New Post
</span></span><span style="display:flex;"><span>    
</span></span><span style="display:flex;"><span>    A1: Input Dialog [
</span></span><span style="display:flex;"><span>         Title: New post
</span></span><span style="display:flex;"><span>         Text: Enter title
</span></span><span style="display:flex;"><span>         Close After (Seconds): 30
</span></span><span style="display:flex;"><span>         Input Type: 540673 ]
</span></span><span style="display:flex;"><span>    
</span></span><span style="display:flex;"><span>    A2: Termux [
</span></span><span style="display:flex;"><span>         Configuration: new_blog_post &#34;%input&#34;
</span></span><span style="display:flex;"><span>         
</span></span><span style="display:flex;"><span>         Working Directory ✕
</span></span><span style="display:flex;"><span>         Stdin ✕
</span></span><span style="display:flex;"><span>         Custom Log Level null
</span></span><span style="display:flex;"><span>         Terminal Session ✕
</span></span><span style="display:flex;"><span>         Wait For Result ✓
</span></span><span style="display:flex;"><span>         Timeout (Seconds): 10
</span></span><span style="display:flex;"><span>         Structure Output (JSON, etc): On ]
</span></span><span style="display:flex;"><span>    
</span></span><span style="display:flex;"><span>    A3: JavaScriptlet [
</span></span><span style="display:flex;"><span>         Code: var uri = &#34;content://net.dinglisch.android.taskerm.fileprovider/external_files/storage/emulated/0/Documents/markor/foosel.github.io/content/blog/&#34; + stdout.trim();
</span></span><span style="display:flex;"><span>         Auto Exit: On
</span></span><span style="display:flex;"><span>         Timeout (Seconds): 45 ]
</span></span><span style="display:flex;"><span>    
</span></span><span style="display:flex;"><span>    A4: Send Intent [
</span></span><span style="display:flex;"><span>         Action: android.intent.action.SEND
</span></span><span style="display:flex;"><span>         Cat: None
</span></span><span style="display:flex;"><span>         Mime Type: text/markdown
</span></span><span style="display:flex;"><span>         Data: %uri
</span></span><span style="display:flex;"><span>         Package: net.gsantner.markor
</span></span><span style="display:flex;"><span>         Class: net.gsantner.markor.activity.DocumentActivity
</span></span><span style="display:flex;"><span>         Target: Activity ]
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-plain" data-lang="plain"><span style="display:flex;"><span>    Task: Commit Blog
</span></span><span style="display:flex;"><span>    
</span></span><span style="display:flex;"><span>    A1: Input Dialog [
</span></span><span style="display:flex;"><span>         Title: Commit Blog
</span></span><span style="display:flex;"><span>         Text: Enter commit message
</span></span><span style="display:flex;"><span>         Close After (Seconds): 30 ]
</span></span><span style="display:flex;"><span>    
</span></span><span style="display:flex;"><span>    A2: Termux [
</span></span><span style="display:flex;"><span>         Configuration: commit_blog &#34;%input&#34;
</span></span><span style="display:flex;"><span>         
</span></span><span style="display:flex;"><span>         Working Directory ✕
</span></span><span style="display:flex;"><span>         Stdin ✕
</span></span><span style="display:flex;"><span>         Custom Log Level null
</span></span><span style="display:flex;"><span>         Terminal Session ✕
</span></span><span style="display:flex;"><span>         Wait For Result ✓
</span></span><span style="display:flex;"><span>         Timeout (Seconds): 10
</span></span><span style="display:flex;"><span>         Structure Output (JSON, etc): On ]
</span></span></code></pre></div><p>&ldquo;New Post&rdquo; queries a post title from the user, calls <code>new_post</code> with that and then opens the new post in Markor.</p>
<p>&ldquo;Commit Blog&rdquo; queries a commit message from the user and calls <code>commit_blog</code> with that.</p>
<p>I created desktop shortcuts for these too and placed all of them, together with Markor, Termux and a browser shortcut, in a new folder &ldquo;Blog&rdquo;.</p>
<p><img alt="Screenshot of the shortcut folder dedicated to my blog." loading="lazy" src="/blog/2023-01-21-hugo-meet-android/shortcuts.jpg"></p>
<p>So, my workflow now consists of pulling, creating a new post, editing it, optionally firing up Hugo to check on the whole thing locally, committing and pushing, all at least without <em>needing</em> to touch the terminal, but always <em>able</em> to if so desired.</p>
<p>It&rsquo;s not perfect, and some app that takes care of all of this from a nice UI would certainly be better (<em>hint hint</em>). But - as this post created entirely from my phone proves - it works for now 😁</p>
<div class="footnotes" role="doc-endnotes">
<hr>
<ol>
<li id="fn:1">
<p>Quick shoutout to <a href="https://pipe.how/write-androidblog/">this post by Emanuel Palm</a> who found himself in a similar situation (prior to boarding a plane to boot) and showed me the path on which I was then able to set up a neat workflow.&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
<li id="fn:2">
<p>You&rsquo;ll obviously have to adjust that and the following bits with your own repo, name and email.&#160;<a href="#fnref:2" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
<li id="fn:3">
<p>Note that I&rsquo;m aware of the existence of <code>hugo new</code>, however it insisted on prefilling the title with the date included and otherwise also felt a bit too inflexible, hence I decided to implement what I wanted directly in bash.&#160;<a href="#fnref:3" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
</ol>
</div>
]]></content:encoded></item></channel></rss>