Nathan Grigg

Safari Web Apps and Composable Tools

I have two or three web pages that I tend to keep open on my desktop Mac. From time to time I have experimented with turning these into web apps, which makes it possible for me to hide them independently of my other web browser windows, helps them remember the appropriate window size, and helps me to not accidentally change them to a different page.

I was happy to discover that Safari makes it easier than ever to convert a page into a web app. Just select “Add to Dock” in the File menu (or share sheet). It puts an icon in the Dock, but you don’t have to leave it there because it also puts an application in ~/Applications.

But one of my pages is an HTML dashboard that is just a local file on my computer. I originally made it this way because it syncs via iCloud Drive, so that I can also view it on my phone or iPad if necessary. For some reason, you can’t make a web app to view a local file.

Simple HTTP server

The good thing about the Mac is that you can work around almost anything, building exactly what you want out of smaller pieces. And in this case, all you need is a little program that responds to HTTP requests with the content of the file.

There are many ways to accomplish this. I think MacOS still comes with Apache installed by default. It is running on my machine, at least. But I don’t like configuring Apache, so I didn’t use this method.

Python can make an HTTP server easily, just run

python -m http.server -b localhost -d /path/to/directory 8203

The -m flag runs the http.server module as if it were a Python script (that is, with __name__ == "__main__"). In this case, it starts up a server with the given options. The -b flag tells it to listen on localhost, so that other computers on your network can’t access the page. Then you give it a directory and a port number. After this you can visit http://localhost:8203/file.html and view the file.

But Python technically serves the entire directory, not just the file. You could write a custom Python script that imported http.server, and probably build exactly what you wanted. But when I want a tiny program, I always seem to gravitate towards Go, even though I tend to hate it for larger programs. I probably like it because you can compile a binary that has no dependencies, which reminds me of Turbo Pascal.

Here is a simple Go program that serves a single file at the port, and redirects any other requests to the base URL:

package main

import (
	"flag"
	"log"
	"net/http"
	"os"
)

func main() {
	bind := flag.String("bind", "127.0.0.1:8011", "The address to listen on.")
	filename := flag.String("file", "", "The file to serve")
	flag.Parse()

	if *filename == "" {
		flag.Usage()
		os.Exit(1)
	}

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		if r.URL.Path == "/" {
			http.ServeFile(w, r, *filename)
		} else {
			http.Redirect(w, r, "/", http.StatusMovedPermanently)
		}
	})

	log.Printf("Starting server at %s", *bind)
	log.Fatal(http.ListenAndServe(*bind, nil))
}

I called it servefile.go, then you just run go build servefile.go and it creates a binary named servefile.

Keep the server alive in the background

If you go the Apache route, MacOS will already keep the server alive for you. If you go the Python or Go route, you need to tell the system to always run your server.

The easiest way is to buy LaunchControl and create a new agent to run your command, checking “Run at load” and “Keep alive no matter what.”

For more information, check out this 13-year-old article on scheduling with launchd.


The best pun

¿Qué dijo una estatua a la otra?

¡No te movái!

In English, “What did one statue say to the other? Don’t move!”

On a kindergarten level, this is already funny, because statues are known for their ability to not move.

But what makes it a pun is that, in a Chilean accent, movái is a homophone of Moai, the well-known Easter Island statues.

In fact, anywhere else in the Spanish-speaking world you would say “No te muevas” (or in Argentina “No te movás”), which would ruin the joke. But in the Chilean voseo form, this becomes “No te movái.” And Chileans, who often drop consonants, especially v’s, and even more so when getting all voseo-folksy, would say “No te moai.


Idea for an app: You ask questions, it gives you answers. If it is wrong, you get $5. It is allowed to say “I’m not sure, but here is my best guess,” in which case there are no guarantees.


Heroes

For Independence Day, we had tickets to the Dodgers game, and my daughter was excited about the prospect of a fireworks show. The fireworks were great, although it was a little awkward as tens of thousands of fans had to sit through an 18-1 blowout just to get to the end of game celebration.

The ceremonial first pitch was thrown out by Rick Monday, Dodgers royalty who, as a player, was before my time but who is known more broadly for his work on the radio broadcasts, which I rarely listen to. Not enough to have any personal feelings toward him as a person or personality.

The July 4th tie-in was the time that Monday “heroically” saved an American flag from a center field protest in 1976 at Dodger Stadium.

I grew up in Idaho, in the 90s, as a member of the Boy Scouts, surrounded by Vietnam veterans. So I absorbed a lot of the content-free “disrespecting America should be illegal” discourse that always completely sidestepped the ideologies of the protests and treated the protesters as rabid America haters. But I also heard the personal stories of men who went through hell, telling themselves that their country needed their sacrifice, only to arrive home and find out that the situation was more nuanced than that.

So I was understandably skeptical about the whole rah-rah America attitude, especially while a whole segment of our leaders are intent on destroying our institutions and calling it patriotism, while a large portion of the population is intent on respecting their authority and calling it patriotism. Of course, it didn’t help that Monday paired up with election denier Blake Treinen to throw out the first pitch. And I wasn’t terribly surprised to find out that at one point Monday tried to save the American flag from Colin Kaepernick as well.

Kudos to the Dodgers, however, for picking Lauren Evans to sing the national anthem. In a time when mediocre white men are shameless enough to claim with a straight face that the existence of a minority in power is evidence of anti-White racism, it is good to be reminded that a Black woman can match and beat their “patriotism”.

And while the Dodgers, mercifully, don’t generally follow the “God Bless America” tradition, they made an exception for Independence Day. But once again, they asked Lauren Evans to sing, and it was good to be reminded that this is her land, her home, my land, my home, their land, their home, and not just Trump’s land, however much he wants to claim it for his own.

I like to think someone in the organization planned the whole thing to piss Rick Monday off. They even managed to show him on the video boards, standing as Evans sang for blessings on our mountains and our prairies, looking bored out of his mind.


Shoseien Garden, Kyoto


Kumatakasha, Fushimi Inari Shrine, Kyoto


Lotus Flower at Shinobazu Pond, Ueno Park, Tokyo


Yanaka Cemetery, Tokyo


Inspired by Nate Anderson, we started reading Lord of the Rings seven months ago and finished today. Various members of the family participated from time to time, but most devoted was my six year old, who didn’t miss a session.


The best hour I’ve spent on YouTube this year: How Hoover Dam Works.


Honestly the most damning part of the Apple revelations are that Tim Cook was personally involved in figuring out the wording of the scare screen. Does he write the Notification Spam too?


Kobo Sleep Screens

We have a half dozen Kobo readers in our family, and the Kobo Libra 2 only comes in two colors, so you don’t always know whose is whose.

By default, the Kobo will show the cover of the book that you are reading, but you can override this by putting a PNG image into the folder .kobo/screensaver. The Libra 2 has a screen dimension of 1264 by 1680, so ideally you match this aspect ratio. You may need to modify some of the energy saving settings; I actually had to make sure that “show current read” and “show book covers full screen” were both set to On.

Then I had ChatGPT make a cartoonified image of each of us reading a book in some setting. Here is mine, which I told it to make “Lord of the Rings” themed. It is goofy but serves its purpose and makes me laugh.


I had a flight from Tokyo that departed on Tuesday and arrived on Monday, so of course I took advantage of the opportunity to stress test some apps. Resaonable handling by Day One (pictured). Very poor handling by Apple’s sleep tracking (not pictured because I don’t even understand where it went wrong).


Shinjuku Gyoen


Edo Castle ruins (Imperial Palace East Gardens)