macOS Shortcuts: Reading a text file without a .txt extension

less than 1 minute read

Today I set out to build some time tracking Shortcuts on macOS. I’m using Ledger’s time keeping capabilities and I wanted to read the last line of my data file.

I ended up wasting a bunch of time because I named the file time.dat. I tried the following set of actions and it kept returning the text time:

  1. File - I set the correct path to time.dat
  2. Split Text by New Lines
  3. Get Last Item from Split Text

This should have returned the last line from the file, but I kept getting time. Finally, I stumbled upon this Reddit post that had the key: the file must have a .txt extension.

I didn’t want to rename the actual file on disk, but the post says you can use the “Set Name” action to rename it within the Shortcut. Now my Shortcut has these actions and it works like a charm:

  1. File - I set the correct path to time.dat
  2. Set name of File to time.txt
  3. Split Text by New Lines
  4. Get Last Item from Split Text

Shortcut to read a text file without a .txt extension

I’m writing this up in hopes of saving someone else from wasting as much time as I did, most likely my future self.