Summarizing Websites with Fabric and Apple Shortcuts

A sleek, modern office scene with a glowing computer screen displaying lines of code and summarized text. The background features abstract, flowing data streams and icons representing shortcuts and commands, symbolizing the seamless integration of automation tools. The overall atmosphere is energetic and futuristic, with a focus on productivity through technology.

Introduction

In my pre­vi­ous arti­cle, I explained the first steps for using Fab­ric to work more effi­cient­ly with LLMs. This was pri­mar­i­ly done through the com­mand line inter­face. As I promised in that arti­cle, I now want to show how Fab­ric can be inte­grat­ed into an Apple Short­cuts work­flow.

As an exam­ple, I will demon­strate how to sum­ma­rize a web­page using the work­flow described in the arti­cle. As a reminder, here’s the CLI com­mand:

wget -qO - https://example.com/my-blog-article | pandoc -f html -t plain | fabric --stream --pattern summarize

My require­ments for the short­cut are:

  1. It should work with every brows­er.
  2. It will be called from the Short­cut Menu.
  3. It will save the result in my Obsid­i­an Vault as a note in a spe­cif­ic fold­er.
  4. The title of the web­page will be used as the title of the note.
  5. The URL of the web­page and the tag “fab­ric” should be saved in the front­mat­ter sec­tion of the note.

The Apple Shortcuts

Orig­i­nal­ly, I intend­ed to imple­ment the Apple Short­cut using the script more or less as it was. The plan was to fetch the URL of the active web­site with the “What’s On Screen” action, pass it as an argu­ment to the “Run Shell Script” action, and then exe­cute the script. How­ev­er, it didn’t work as intend­ed. While the URL is cor­rect­ly iden­ti­fied with­in the Short­cuts envi­ron­ment, it turns into a link to a local copy of the web­page when the “Run Shell Script” action is called. This can be test­ed with a sim­ple Short­cut.

A screenshot of an Apple Shortcuts interface titled “URL-Test.” The shortcut is set to receive URLs and articles as input from “What’s On Screen.” The shortcut then runs a shell script with the command echo $1, using the zsh shell. The script’s input is passed as arguments, and the result is displayed. Options on the right allow the shortcut to be pinned in the menu bar, shown in the share sheet, and set to receive input from the screen. Various other settings, like “Run as Administrator” and “Show on Apple Watch,” are also visible but not enabled.

Just run this short­cut when a brows­er is active, and you’ll see the prob­lem. 😉

In the end, I took advan­tage of this strange behav­ior by sim­ply pip­ing the con­tent of the file locat­ed at the path pro­vid­ed as an argu­ment with the cat com­mand to the fab­ric com­mand.

Before start­ing to define the short­cut, there is anoth­er issue to solve. Since the “Run Shell Script” action doesn’t run in the nor­mal envi­ron­ment of the Ter­mi­nal pro­gram, it can’t access, for exam­ple, the search path def­i­n­i­tions that are set in the .zshrc con­fig­u­ra­tion file. This means it won’t find the fab­ric com­mand or any of the alias def­i­n­i­tions for eas­i­ly call­ing fab­ric, as I explained in the pre­vi­ous arti­cle.

Shortcut definitions

Before start­ing to define the short­cut, there is anoth­er issue to solve. Since the “Run Shell Script” action doesn’t run in the nor­mal envi­ron­ment of the Ter­mi­nal pro­gram, it can’t access, for exam­ple, the search path def­i­n­i­tions that are set in the .zshrc con­fig­u­ra­tion file. This means it won’t find the fab­ric com­mand or any of the alias def­i­n­i­tions for eas­i­ly call­ing fab­ric, as I explained in the pre­vi­ous arti­cle.

Here is the shell con­fig­u­ra­tion that will be used in the script:

# Add the Go binary directory and the path to homebrew commands to the existing PATH environment variable export
export PATH="$PATH:$HOME/go/bin:/opt/homebrew/bin/"

# Check if the fabric-bootstrap.inc file exists in the specified directory
# If the file exists, source it to load its configurations and variables
if [ -f "$HOME/.config/fabric/fabric-bootstrap.inc" ]; 
    then . "$HOME/.config/fabric/fabric-bootstrap.inc"; 
fi

This con­fig­u­ra­tion adds the path infor­ma­tion for the Fab­ric as well as for Home­brew-installed com­mands (in this case, pan­doc). The sec­ond part loads the alias def­i­n­i­tions, allow­ing you to use just summarize instead of fabric -sp summarize.

Now, let’s take a look at the script:

source $HOME/.fabenv
cat $1 | pandoc -f html -t plain | -sp summarize

First, it sources the shell con­fig­u­ra­tion. Then, it calls the com­mand cat $1. Since the vari­able $1 con­tains the local path to the web­page, it pipes the entire HTML, which includes a lot of extra ren­der­ing infor­ma­tion, through the pan­doc com­mand to clean it up before pip­ing it through the fabric/summarize call.

With the script defined, let’s look at the entire Short­cut:

And here’s how the process works:

  1. The URL and title of the web­page are passed to the short­cut and stored in the cor­re­spond­ing vari­ables.
  2. The title will be cleared of any spe­cial char­ac­ters that might cause issues in Obsid­i­an or Find­er.
  3. The “Run Shell Script” action receives the path to the local HTML file through the URL vari­able.
  4. The script will be exe­cut­ed as described above.
  5. The out­put of the shell script is stored in the Text vari­able. The note is then assem­bled in a text block, includ­ing the front­mat­ter sec­tion and foot­er.
  6. This text is then saved in the Obsid­i­an Vault. To save the note in the Obsid­i­an Vault, I use the short­cut exten­sion Actions for Obsid­i­an with the “Cre­ate Note” action. Alter­na­tive­ly, you can save the note with the “Save File” action, but when work­ing with Obsid­i­an, it’s worth invest­ing in Actions for Obsid­i­an.

Some web­pages are resis­tant, and the script can’t fetch them. In such cas­es, at least when using Ope­nAI, the short­cut will save a note with some place­hold­er text.

Sum­ma­ry and Out­look on Future Appli­ca­tions

I hope that with this arti­cle, I not only intro­duced a use­ful tool but also pro­vid­ed a start­ing point for cre­at­ing your own solu­tions on how to inte­grate Fab­ric into Apple Short­cuts.

The short­cut is cer­tain­ly not yet ful­ly refined. For exam­ple, error han­dling is miss­ing. I can also imag­ine that a selec­tion dia­log could be used to choose dif­fer­ent pat­terns. Addi­tion­al­ly, the work­flows cur­rent­ly run local­ly on my Mac­Book Pro, so I haven’t test­ed whether the “Remote Shell Script” action can exe­cute the Fab­ric com­mand on a serv­er. As long as no local LLMs are involved, a Rasp­ber­ry Pi should suf­fice. This way, a short­cut could also work on an iPad or iPhone. I’m cur­rent­ly work­ing on that, so stay tuned.

Feel free to leave crit­i­cism, cor­rec­tions, and praise in the com­ments.

Leave a Reply

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