Sound The Sea SOUND THE SEA

Terminal beans

May 2, 2024

This is fun, a shop selling coffee beans over SSH.

ssh terminal.shop

Terminal shop

Handy commit message generator

Apr 28, 2024

I will surely find a use for this commit message generator, and this quick one-liner from DevOps Toolbox to pipe it right into your Git commit make it even better:

git commit -m '$(curl -s https://whatthecommit.com/index.txt)'

Current favourites:

commented out failing tests

and

This should work until december 2013.

... both hit all too close to home, I'm afraid.

iOS Simulator remote control from NeoVim

Apr 27, 2024

If you're a developer using NeoVim on the Mac you might want to check out my new plugin simctl.nvim.

Part of my day job involves writing apps in React Native, and so I spend a good amount of time developing and running apps on the iOS Simulator. I wanted a way to automate tasks that slow me down and make me take my hands off the keyboard.

example image

The most common uses of this plugin for me is automation for running Expo apps and shortcuts for quitting and reinstalling Expo Go. I have also set up a lot of useful key mappings so I have shortcuts for commonly used Simulator settings such as adjusting the content size for accessibility testing, as well as quickly switching between light and dark mode on the device.

Using Apple Shortcuts to run scripts

Jan 27, 2024

I recently had a minor argument with Apple Shortcuts about running a Python script. In the end the solution was simple so I thought I'd share it here.

My goal was to have a simple way converting downloaded bank statements in CSV format to the CSV format that YNAB, or You Need a Budget, expects. I've made it so this shortcut is available when I right click a file in the Finder.

The specifics of the script isn't important but here's an abbreviated version of it to give you a basic boilerplate to start from:

import os
import csv
import sys
import locale

input_file_path = sys.argv[1]
input_file_name = os.path.basename(input_file_path)
input_file_dir = os.path.dirname(input_file_path)
output_file = os.path.join(input_file_dir, "ynab-" + input_file_name)

with open(input_file_path, "r") as file, open(output_file, "w") as out:
  reader = csv.reader(file, delimiter=';')
  writer = csv.writer(out, delimiter=',', quoting=csv.QUOTE_NONNUMERIC)
  header = next(reader)

  writer.writerow(["Date","Payee","Memo","Outflow","Inflow"])

There's a couple useful parts to this in conjuction with Shortcuts:

  • The script reads the input file name as sys.argv[1]
  • It takes the input file name and prepends ynab- to distinguish the converted file

I recommend getting your script working from the terminal before you try to use it in Shortcuts; sometimes Shortcuts will just silence any errors completely and sometimes it'll show you what's wrong but it's much clearer to figure that out from a command line or a debugger. Run the script with:

python script.py input_file.csv

If all goes well it should write a ynab-input_file.csv file.

Now to get your script into the context menu of Finder!

Open the Shortcuts app on your Mac and create a new Shortcut:

  1. Add a Run Shell Script action
  2. Choose python3 as your Shell and select to Pass Input as arguments
  3. Paste in your working Python script

Then, in the info pane of your Action, select to Use as Quick Action in the Finder.

That's it. You're done. When you right click the file you should see your new action under the sub menu Quick Actions.

If, like me, you have a problem where your script silently fails to run, try giving Finder full disk access on your Mac: open System Settings, search for Full Disk Access and add Finder to the list of apps with access to your whole disk.

104 Things to learn

Jan 12, 2024

I am looking forward to Tom Whitwell's list of 52 things I learned in 2023 every year, and this year Leo Kottke published his own. Favourites from the two:

Tom Whitwell's list:

  1. Scotland’s forest cover is nearly back to where it was 1,000 years ago, while England has risen to levels last seen in 1350. [Hannah Ritchie]

Leo Kottke's list:

  1. Baby scorpions are called scorplings.