decorative image. Connected terminal seesions with colored band on top the title FABRIC.

Introduction

In my last blog post, I pro­vid­ed an out­look on run­ning a short­cut that sum­ma­rizes a web­page on an iPhone or iPad. Since it’s not pos­si­ble to run Go on iOS, we need a com­put­er that can be reached via SSH from your device. For con­stant access, it should prefer­ably be up and run­ning 24/7. For me, my Mac­Book Pro would be a good choice, but when I use my iDe­vices, I close the lid, so the iDe­vices have no chance to con­nect.

Choosing the Right Machine

I have two machines run­ning all the time in my net­work: a Syn­ol­o­gy NAS and a Rasp­ber­ry Pi 4 with 4GB of RAM run­ning Ubun­tu 24.04 LTS. Because I am not very expe­ri­enced in cross-com­pil­ing with Go or cre­at­ing Dock­er images, I decid­ed to go with my Rasp­ber­ry Pi.

Since I’m only run­ning Fab­ric with cloud LLMs, in my case with Ope­nAI, there is no need for a lot of com­put­ing pow­er, so the Rasp­ber­ry Pi is more than suf­fi­cient.

But in the end, you can use any com­put­er sys­tem that runs Go.

Preconditions

You need to have a lit­tle exper­tise in Linux/Unix and the Com­mand Line Inter­face (CLI). Besides the instal­la­tion of Go (see the next chap­ter), you should also set up SSH on your Rasp­ber­ry Pi, because the Short­cut will call Fab­ric via “Run Script over SSH”. You should also install git to access the Fab­ric repos­i­to­ry on GitHub, ffmpeg for run­ning the yt com­mand, and wget to fol­low some of my exper­i­ments lat­er on:

sudo apt install git ffmpeg wget

Installation of Go and Fabric

If Go isn’t already installed, you have to install it first. I fol­lowed the “offi­cial” method as described on the GO web­site:

  1. Ensure there is no pre­vi­ous ver­sion installed by check­ing if the fold­er /usr/local/go exists. If it does, delete it with sudo rm -rf /usr/local/go.
  2. Down­load the lat­est arm64 ver­sion for the Rasp­ber­ry Pi.
  3. Install Go. Depend­ing on where you down­loaded the archive, for me it was: tar -C /usr/local -xzf $HOME/Downloads/go1.23.0.linux-amd64.tar.gz.
  4. Add the nec­es­sary path infor­ma­tion. For the set­up in my case $HOME/.zshrc. For the short­cut call, I cre­at­ed and used a spe­cial shell lim­it­ed con­fig­u­ra­tion file, sim­i­lar to my macOS set­up, called .fabenv, and added the paths there:
     export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin
  5. Install Fab­ric direct­ly from the repos­i­to­ry:
    go install github.com/danielmiessler/fabric@latest.
  6. Set up Fab­ric with fabric --setup. Before doing so, read the next para­graph.
  7. Install yt if you want to ana­lyze YouTube videos: go install github.com/danielmiessler/yt@latest, but be sure to add your YouTube API key.

Troubleshooting Fabric Setup

When I wrote this, the set­up failed at the end when copy­ing the pat­terns, with the error stream error: stream ID 3; CANCEL; received from peer happened. How­ev­er, the instal­la­tion and set­up com­plet­ed all the nec­es­sary tasks. The only things miss­ing are the fold­ers for the pat­terns, ses­sions, and con­texts. After copied them from my macOS instal­la­tion, Fab­ric ran fine. I hope some­one can fig­ure out why the set­up fails so I can delete this para­graph ;-). If you use anoth­er com­put­er as a serv­er or anoth­er OS on your Rasp­ber­ry Pi, it might work.

Update 2024/09/23: When using an Eth­er­net cable to con­nect the Rasp­ber­ry Pi 4, every­thing works fine. This sug­gests that the issue may be relat­ed to the speed or band­width lim­i­ta­tions of the Wi-Fi chip.

Validating the Installation

All the oth­er infor­ma­tion in my blog post Instal­la­tion and Get­ting Start­ed with Fab­ric is still valid. For exam­ple:

echo "Two parrots on a skyscraper rooftop" | fabric --stream --pattern create_logo

works just like on the Mac.

The “Run Script over SSH” Mystery

As I already men­tioned in my pre­vi­ous blog post Sum­ma­riz­ing Web­sites with Fab­ric and Apple Short­cuts, there is some mys­te­ri­ous behav­ior with Short­cut vari­ables inside and around the shell action, both local and remote.

Passing the URL

For the “Run Script over Shell” action, I tried sev­er­al ways to pass the URL into the action until I found a hint some­where on the web that the eas­i­est way is just to use vari­ables inside the script box:

The image shows a macOS Shortcut named “iOS WebSummary.” This shortcut automates the process of summarizing a webpage’s content using SSH to execute a command on a remote server.Explaination see text

As you can see, this is an exam­ple in the macOS Short­cuts app, and it works fine. You can use this solu­tion instead of the workaround in my pre­vi­ous blog post.

I ini­tial­ly thought that if it works on macOS, it should also work in the iOS/iPadOS Short­cuts app. So, I copied the short­cut. How­ev­er, it didn’t work at all, which was frus­trat­ing.

After hours of exper­i­ment­ing, I found that this con­struct works, though I’m not sure why the easy one line com­mand does­n’t work:

A close-up screenshot of a “Run script over SSH” configuration within a macOS Shortcut. The script sources an environment file (~/.fabenv), fetches content from a URL using wget, stores it in a variable (output), and then pipes the output to a command (fabric -sp summarize) for summarization. SSH details like Host and Port are partially visible.

Using curl Instead of wget

There is anoth­er com­mand to down­load the con­tent of URLs in the Lin­ux and macOS tool­box: curl. Out of curios­i­ty, I tried this com­mand. To my sur­prise, there is no need for the com­plex con­struc­tion that I had to use with wget.

A command line interface with a dark background and light text displays two commands. The first command, source ~/ .fabenv, sources an environment file from a hidden directory in the user’s home directory. The second command, curl 🌐URL | fabric -sp summarize, uses ‘curl’ to fetch data from a placeholder URL represented by a globe emoji, then pipes it into ‘fabric’ with the options ‘-sp summarize’. This setup is relevant for shell scripting or running scripts over SSH.

Although I’ve been using wget for ages, I think I have to switch over to curl. Because of all the trou­ble, I didn’t go the extra mile to extract the text from the HTML with pandoc. So this will be the pre­ferred solu­tion.

An Unexpected Working Solution

For the sake of com­plete­ness, here is anoth­er approach. Dur­ing my exper­i­ments, I made a small mis­take and end­ed up with this com­mand, which sur­pris­ing­ly works as well:

A screenshot showing a modified “Run script over SSH” configuration in a macOS Shortcut. The script sources an environment file (~/.fabenv), then uses echo to pass a URL (represented as a variable URL) to the fabric command (fabric -sp summarize) for summarizing web content.

I assume it might be because the vari­able URL is inter­nal­ly treat­ed as some kind of struc­ture that always has all infor­ma­tion avail­able, and some mag­ic fetch­es the right val­ue for a giv­en con­text. For exam­ple, if you just echo the vari­able URL, the out­put is sim­ply the URL.

The iOS/iPasOS Shortcut

Screenshot of an Apple Shortcut interface in dark mode, displaying various actions. The actions include retrieving URLs, setting variables, replacing files, running scripts over SSH, and summarizing text. Detailed description in the text.

The work­flow is the same as in the macOS work­flow:

  1. Use Receive What’s Onscreen to work in all web browsers.
  2. Assign the URL of the active web­site to the vari­able URL.
  3. Assign the title to the vari­able name.
  4. Delete : and / in the vari­able name, because these char­ac­ters cause issues in file names (this could be extend­ed to oth­er char­ac­ters like ?).
  5. Use Run Script over SSH with the IP address or name of your serv­er, the user and pass­word, and the script dis­cussed above.
  6. Put the result into the vari­able summary.
  7. Cre­ate the note for Obsid­i­an in a text box, includ­ing the prop­er­ties sec­tion and, if need­ed, a foot­er area.
  8. Save it with the Cre­ate Note action of the Action­ForOb­sid­i­an (AFO) Short­cuts Exten­sion App.
  9. Use “AFO” to open the new­ly cre­at­ed note.

I use “AFO” to save the note in my Obsid­i­an vault because it’s very easy to han­dle. It is worth invest­ing in this exten­sion, as its col­lec­tion of Obsid­i­an-relat­ed actions helps bridge the gap between the Short­cuts app and Obsid­i­an. Nev­er­the­less, you can also use the save-file action or move the result to the Notes app.

Conclusion

This is just an exam­ple of how to inte­grate a remote­ly run­ning Fab­ric instal­la­tion into iOS/iPadOS Short­cuts. This approach opens up a uni­verse of pos­si­bil­i­ties. Any­thing that runs on a remote machine and con­sumes text input or cre­ates text out­put on the ter­mi­nal (stdin/stdout) can be used to cre­ate com­plex work­flows with Fab­ric, there­by eas­i­ly becom­ing AI-sup­port­ed.

I hope this blog post is over­all help­ful, despite the lit­tle hur­dles. It would be great if some­one could explain the mys­te­ri­ous behav­ior of the URL vari­able. I would also love to learn how to avoid the Fab­ric set­up error. Crit­ics, kudos, more ideas, and what­ev­er else—please leave them in the com­ments.

Leave a Reply

Your email address will not be published. Required fields are marked *