Making flippy floppy

In the wake of last Friday’s ground stoppage, the New York Times pointed me to this article (that should be a gift link) from just a week earlier about outdated computer technology still in use in air traffic control. I was struck by one of the terms used in the article.

The article is titled “Just 2 More Years Until We’re Done With Floppy Disks, F.A.A. Says,” and it includes an explanation of what those mysterious “floppy disks” are for its younger readers.

Most adults barely remember floppy disks, even if they are old enough to have used them. And the idea that such antiquated technology is still used for important jobs two decades into the 21st century seems laughable.

They were originally produced in the early 1970s at an eight-inch diameter, they shrank to 5¼ inches and then 3½ inches.

The original disk was indeed “floppy,” with a soft plastic case. Later versions that became popular in the mid-80s had harder plastic shells, and didn’t flop anymore, but the name stuck.

Different sizes of floppy disk

Image from Tom’s Hardware.

There’s an Apple angle to this. When I bought my first Mac in the spring of 1985, system software, the programs (“apps” hadn’t been invented yet), and my document files were all stored on the 3½-inch medium described above.

But what prompted me to write this was the strong memory that Apple was adamant that these were not “floppy disks.” Apple felt that that term was appropriate for the old-fashioned 5¼-inch disks used in those terribly antiquated IBM PCs,1 but should never be used for the sleek, sturdy, and hard-shelled media used in Macs. Apple insisted on calling the 3½-inch variety “diskettes.”

The argument was that the stiff plastic shell made them not floppy.2 The actual magnetic disk inside the shell was still floppy, but you were never supposed to see that.

As I recall, the Mac community of the time was pretty good about sticking to Apple’s preferred terminology. I still think of floppy disks as being the 5¼-inch variety, but apparently I’m in the minority. As time went by, everything that wasn’t a hard disk became floppy.


  1. Also used in the Apple II series, but they didn’t say that part out loud. Apple did phase in 3½-inch disks for its IIs, but most were still running on the 5¼-inch variety. ↩

  2. There is no way to talk about this stuff without it sounding like innuendo. ↩


Some new Typinator abbreviations

I mentioned in my last post that I’m learning Julia. I intend to use it for mathematical work, and because Greek letters are used in formulas I’ll be turning into programs, it seemed like a good idea to make it easier to include Greek letters in my code as variable names. Over the weekend, I made a simple Typinator set for that purpose.1

You can download the Typinator set if you think it would be helpful to you. Here’s a list of the Greek letters and their abbreviations.

Letter Abbrev Letter Abbrev
α ,,a Α ,,A
β ,,b Β ,,B
γ ,,g Γ ,,G
δ ,,d Δ ,,D
ε ,,e Ε ,,E
ζ ,,z Ζ ,,Z
η ,,y Η ,,Y
θ ,,th Θ ,,TH
ι ,,io Ι ,,IO
κ ,,k Κ ,,K
λ ,,l Λ ,,L
μ ,,m Μ ,,M
ν ,,n Ν ,,N
ξ ,,x Ξ ,,X
ο ,,on Ο ,,ON
π ,,pi Π ,,PI
ρ ,,r Ρ ,,R
σ ,,s Σ ,,S
τ ,,tt Τ ,,TT
υ ,,u Υ ,,U
φ ,,ph Φ ,,PH
χ ,,ch Χ ,,CH
ψ ,,ps Ψ ,,PS
ω ,,om Ω ,,OM

I never use many of these symbols because they’re too easy to confuse with Latin letters that look the same; this is especially true for the capitals. But once I got started, I just did the whole alphabet anyway. Maybe I’ll delete some of them as time goes on.

The set is defined with a double comma as the common prefix, and the abbreviations expand immediately—no waiting for a word break character.

Greek letters group information

You may be wondering why I use ,,y as the abbreviation for η. When I need to deal with a rotated coordinate system, ξ and η are typically the symbols I use for the rotated x and y coordinates, so it made sense (to me, anyway) for η to be ,,y.

Coordinate systems

Other symbols I often use are in another set, Math symbols:

Symbol Abbrev Symbol Abbrev
× ,,* ÷ ,,/
∞ ,,8 ∴ ,,…
⇒ ,,> ⇔ ,,<>
′ ,,ft ″ ,,in

I tend to use the prime and double prime symbols for feet and inches, hence the ft and in in their abbreviations. In the past, I’ve used different abbreviations for some of these, like ;times and ;divide for × and ÷.

A note on the downloads: The two Typinator sets are saved on the server as zip files. Depending on how your browser is configured, they may or may not expand immediately when downloaded. Once they’re expanded, you can add them to your Typinator setup by double-clicking or dragging them into the Typinator window.

Simple little automations like this often save me more time than the more complex ones I often write about. We’ll see how these work out.


  1. The Julia REPL has a LaTeX-like way to enter Greek letters, but I want to be able to enter them in my text editor, BBEdit, too. ↩


Steve, Monty, and Julia

I don’t make a habit of reading obituaries, but I’m glad I clicked the link to this one in yesterday’s New York Times (that should be a gift link). Steve Selvin was a statistician who got his Ph.D. at the University of California, Berkeley, and taught there for many years. He got into the Times because of a probability puzzle he came up with in 1975: the Monty Hall Problem.

I won’t explain the problem here. Most of you already know it, and those who don’t can read the setup in the Wikipedia article. I do want to praise the Times for the cute little interactive game they included in Selvin’s obituary. It allows you to be a Let’s Make a Deal contestant and run through the problem again and again (with your computer playing the Monty Hall role) until you’re convinced that the “switching my choice” strategy is distinctly better than the “sticking with my original choice” strategy. I doubt you have the patience to play it enough times to confirm that switching wins 2/3 of the time and sticking wins 1/3 of the time.

I was less pleased with the explanation the Times gave for the probabilities:

After the first reveal, you have two doors, so you should have a 50-50 chance. Right? But you don’t. The host hasn’t randomly eliminated a door; he has deliberately revealed a goat, using his knowledge of where the car is. Your original door still has a one-in-three chance of hiding the car, while switching gives you a two-in-three chance of winning.

It’s right, of course, but it doesn’t strike me as an actual explanation—it sounds more like a restatement of the answer. To me, the way to think of it is to consider the winning strategy:

If you chose the door with a car behind it on your first guess—which will happen 1/3 of the time—you will win by sticking with that door. If you chose one of the doors with a goat behind it on your first guess—which will happen 2/3 of the time—you will win by switching to the door that Monty didn’t open. Therefore, switching gives you a 2/3 chance of winning.

Everyone’s different, so maybe you don’t need those extra words and the Times explanation is sufficient. Not for me, though.

I mentioned above that although you could play the game in the obituary enough times to get a decent estimate of the probabilities, most of us don’t have that kind of patience. The better way to run lots of simulations in a short time is to use a random number generator to have the computer do all the selecting. I’ve been meaning to try out the Julia programming language for quite a while; this seemed like a good problem to start with.

Here’s my script, switch.jl, for running 10,000 simulations using the “switch” strategy:

 1:  #!/usr/bin/env julia
 2:  
 3:  # Parameters
 4:  N = 10_000    # Number of trials
 5:  m = 0         # Number of wins
 6:  
 7:  # Loop through N trials, counting the number of wins
 8:  for i in 1:N
 9:    # Behind-the-scenes preparation
10:    carDoor = rand(1:3)
11:    goatDoors = [j for j in 1:3 if j != carDoor]
12:    
13:    # Player makes initial choice
14:    playerDoor = rand(1:3)
15:    
16:    # Monty chooses an available goat door
17:    if playerDoor == carDoor
18:      # Pick either of the two available
19:      montyDoor = goatDoors[rand(1:2)]
20:    else
21:      # Pick the one available
22:      montyDoor = [j for j in goatDoors if j != playerDoor][1]
23:    end
24:    
25:    # Player switches to the other door
26:    playerDoor = [j for j in 1:3 if (j != montyDoor) && (j != playerDoor)][1]
27:    
28:    # Increment m if the player wins
29:    if playerDoor == carDoor
30:      global m += 1
31:    end
32:  end
33:  
34:  # Print the winning fraction for this strategy
35:  println(m/N)

Because I’m new to Julia, I put in lots of comments, so I doubt there’s much need for more explanation. I will say, though, that I suspect a real Julia programmer wouldn’t use list comprehensions as often as I did. There’s probably a function for removing items from a list that’s more elegant than what I did in Lines 11, 22, and 26. I just don’t know what that is yet.

My script for running 10,000 simulations of the “stick” strategy, cleverly named stick.jl, is basically the same:

 1:  #!/usr/bin/env julia
 2:  
 3:  # Parameters
 4:  N = 10_000    # Number of trials
 5:  m = 0         # Number of wins
 6:  
 7:  # Loop through the N trials, counting the number of wins
 8:  for i in 1:N
 9:    # Behind-the-scenes preparation
10:    carDoor = rand(1:3)
11:    goatDoors = [j for j in 1:3 if j != carDoor]
12:    
13:    # Player makes initial choice
14:    playerDoor = rand(1:3)
15:    
16:    # Monty chooses an available goat door
17:    if playerDoor == carDoor
18:      # Pick either of the two available
19:      montyDoor = goatDoors[rand(1:2)]
20:    else
21:      # Pick the one available
22:      montyDoor = [j for j in goatDoors if j != playerDoor][1]
23:    end
24:    
25:    # Player sticks with original choice; do nothing
26:    playerDoor = playerDoor
27:    
28:    # Increment m if the player wins
29:    if playerDoor == carDoor
30:      global m += 1
31:    end
32:  end
33:  
34:  # Print the winning fraction for this strategy
35:  println(m/N)

The only difference is in Lines 25–26, where I’m basically doing a no-op.

These scripts give different answers each time they’re run because the random number generator starts with a different seed, but the answers are always close to 0.67 for switch.jl and 0.33 for stick.jl. As expected.

Are 10,000 simulations enough? Well, the 95% confidence interval can be calculated through this formula:

±1.96p(1−p)N

which works out to ±0.009 for both strategies. So 10,000 simulations is fine as long as we’re willing to accept the second decimal place to be off by one every now and then.


Images, the clipboard, and AppleScript

Last week, my SnapClip macro crapped out with an error message. In the process of fixing it, I learned something about AppleScript that probably won’t ever help me in the future.

SnapClip is a Keyboard Maestro macro that puts a graphical user interface on a Python script, process-screenshot. The problem that led to the error was a particular branch of process-screenshot: the branch that puts the screenshot onto the clipboard. I’m not going to rehash the design of SnapClip or process-screenshot here—you can read the old post about them if you want the details.

The branch of process-screenshot that failed runs the impbcopy command-line utility written by Alec Jacobson over a decade ago. I’ve had impbcopy running successfully on my Macs for many years, but last week it failed with the error message

Bad CPU type in executable

I assumed the problem was that impbcopy had been compiled back when I was using an Intel Mac, and it had continued to work because of Rosetta. I thought that because I had Rosetta installed before, it would be updated along with macOS 27, but it wasn’t. Running

softwareupdate --install-rosetta

as described on the Rosetta page got SnapClip working again.

But macOS 27 is the end of the road for Rosetta, so it seemed like a change was due. I installed the Xcode Command Line Tools and tried to recompile impbcopy for Apple Silicon, but that failed with error messages that I couldn’t interpret because I’m not an Objective-C programmer. So I had four options:

  1. Learn enough about gcc/Objective-C/clang to get the compilation to work. Even if I could do this, I assumed it would be a lot of work with no future value for me.
  2. See if I could rewrite the SnapClip macro to use Keyboard Maestro features to put the image on the clipboard. This was more appealing, but I really liked the way the macro was structured and preferred to leave it as a GUI wrapper.
  3. Look into using Shortcuts to put the image on the clipboard and—if it can—replace the call to impbcopy with an equivalent call to the shortcuts utility. But I hate Shortcuts and would rather avoid it if possible.
  4. Work out an AppleScript solution and put a call to osascript into process-screenshot. I knew that AppleScript has commands for reading files and putting things on the clipboard, so I went with this, even though AppleScript may be more of a dead end than Objective-C.

Apple’s online documentation for AppleScript sucks, but I have three old AppleScript books that collectively weigh over nine pounds:

The answer (more or less) was in Learn AppleScript and led to just a couple of changes to process-screenshot. Here’s the new version:

python:
 1:  #!/usr/bin/env python3
 2:  
 3:  import tempfile
 4:  from PIL import Image
 5:  import os
 6:  import subprocess
 7:  import shutil
 8:  from datetime import datetime
 9:  import urllib.parse
10:  import argparse
11:  
12:  # Handle the arguments
13:  desc = 'Process a screenshot saved to a file.'
14:  ep = '''If a title is given, it saves the image to a file on the
15:  Desktop with a filename of the form yyyymmdd-title.png.
16:  If no title is given, the image is put on the clipboard and the
17:  upload option is ignored.'''
18:  parser = argparse.ArgumentParser(description=desc, epilog=ep,
19:            formatter_class=argparse.RawDescriptionHelpFormatter)
20:  parser.add_argument('-b', '--background', help='add desktop background border', action='store_true')
21:  parser.add_argument('-u', '--upload', help='upload to images directory and print URL', action='store_true')
22:  parser.add_argument('-t', '--title', help='image title', type=str)
23:  parser.add_argument('ssfile', help='path to screenshot file')
24:  args = parser.parse_args()
25:  
26:  # Parameters
27:  type = "png"
28:  bgcolor = (85, 111, 137)
29:  border = 32
30:  optimizer = '/Applications/ImageOptim.app/Contents/MacOS/ImageOptim'
31:  ascript = f'set the clipboard to (read POSIX file "{args.ssfile}" as picture)'
32:  
33:  # Add a desktop background border if asked for
34:  if args.background:
35:    snap = Image.open(args.ssfile)
36:    # Make a solid-colored background bigger than the screenshot.
37:    snapsize = tuple([ x + 2*border for x in snap.size ])
38:    bg = Image.new('RGBA', snapsize, bgcolor)
39:    bg.alpha_composite(snap, dest=(border, border))
40:    bg.save(args.ssfile)
41:  
42:  # Optimize the file
43:  subprocess.run([optimizer, args.ssfile], stderr=subprocess.DEVNULL)
44:  
45:  # Save it to a Desktop file if a title was given; otherwise,
46:  # save it to the clipboard
47:  if args.title:
48:    sdate = datetime.now().strftime("%Y%m%d")
49:    desktop = os.environ['HOME'] + "/Desktop/"
50:    fname = f'{desktop}{sdate}-{args.title}.{type}'
51:    shutil.copyfile(args.ssfile, fname)
52:    bname = os.path.basename(fname)
53:  
54:    # Upload the file and print the URL if asked
55:    if args.upload:
56:      year = datetime.now().strftime("%Y")
57:      server = f'user@server.com:path/to/images{year}/'
58:      port = '123456789'
59:      subprocess.run(['scp', '-P', port, fname, server])
60:      bname = urllib.parse.quote(bname)
61:      print(f'https://leancrew.com/all-this/images{year}/{bname}')
62:  else:
63:    subprocess.run(['osascript', '-e', ascript])
64:  
65:  # Delete the temporary file
66:  os.remove(args.ssfile)

The changes are:

The AppleScript that does the work is just one line:

set the clipboard to (read POSIX file "<name of file>" as picture)

Very simple, and I suspect it will work for quite a while. I feel certain that Apple would like to kill AppleScript, but I don’t think it can—too many valuable customers (a group that doesn’t include me) would get very angry at having their longstanding automations die.

One thing that kind of surprised me was the as picture part of the command. Learn AppleScript says that you typically have to include an image type in the command: as GIF picture or as JPEG picture or as TIFF picture. The book suggests that a bare as picture is supposed to work only on PICT images. Never heard of a PICT image? That’s probably because it was the native Mac image format back in the classic days. It was one of Bill Atkinson’s contributions to the Macintosh Toolbox. Nobody saves image files as PICTs anymore.

And yet the unadorned as picture works. I created this test image in Acorn,

Test image

and saved it in several formats: BMP, GIF, HEIC, JPEG, JPEG 2000, PNG, and TIFF. I put the files in a folder named clipboard-test on my Desktop,

Folder of images

and ran this AppleScript for each of the different file extensions:

applescript:
set filePath to path to desktop folder as text
set imageFile to (filePath & "clipboard-test:Test image.bmp") as alias
set the clipboard to (read file imageFile as picture)

Each time I ran the script, the clipboard was loaded with the image, no matter which file was being read. I didn’t have to specify the format.

I suspect that if I were using AppleScript to write image data to a file, it wouldn’t be as forgiving. But process-screenshot uses Python and Pillow to save image files, so I don’t need to worry about AppleScript’s idiosyncrasies for that aspect of the script.