macOS Shortcuts: Reading a text file without a .txt extension
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
:
- File - I set the correct path to
time.dat
- Split Text by New Lines
- 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:
- File - I set the correct path to
time.dat
- Set name of File to
time.txt
- Split Text by New Lines
- Get Last Item from Split Text
I’m writing this up in hopes of saving someone else from wasting as much time as I did, most likely my future self.