I hope it’s OK to promote blog posts I write regarding use of macOS.
The latest one shows how to add an item to the Finder “right-click” context menu, and the example calls a script to restore the most recent backup of a file.
right-click on a file
select “Restore from Time Machine”
file is trashed (recoverable using Trash’s Put Back feature)
most recent backup of that file is restored from Time Machine
This takes a seconds or two, depending on the size of the file in question. Most importantly this saves interrupting my workflow by having to opening the Time Machine interface and zooming through all those windows looking for the file.
You could also install the script to be able to use it from Terminal command line.
Sorry for not seeing this sooner, @gingerbeardman—it’s very cool! I tried setting it up using FiScript here, but struck out on getting the shell scripts updated to match my system.
Have you thought about doing it via Shortcuts, which I think can do the necessary bits, and which might be able to query the user for the various volume names necessary to construct the tmutil command?
There’s a way I can automatically figure out the TM path (using tmutil itself) I just haven’t had time to do that yet. The result will be one script for USB or NAS or any combination of multiple drives.
Shortcuts: I don’t have any real interest in it on macOS at this time. But I’ll give it a look at some point soon.
Aha! Figuring out the Time Machine path using tmutil would be fabulous, since that’s where I suspect my problems with modifying the script happened.
I’m not a big fan of Shortcuts either, but where I’m going with this is a way of packaging your shell script into something that any Monterey-using Mac can use with minimal fuss.
If we can get it there, I’ll definitely be writing a full article about this, since it’s shocking to me that no one before you has realized we need a “restore this particular file” command for Time Machine before. Or at least implemented it!
I’m thinking on first run the Shortcut could check to see if trash is installed and if not install it (download shell script and make it executable). Worries me that this is a bit invasive.
My setup is quite peculiar (System installed on internal SSD, User folder on external SSD). That makes my version of these scripts quite different what is probably needed for the standard user. Will have to spend some time setting up a TM backup of an old laptop to see how the folders are different to be able to create one script that works for all.
I have a clean-up script that runs every night. The key line is
delete file (tThisFile as alias)
I can verify that 1) tThisFile is moved to the Trash by this command, and 2) right-clicking the file inside the Trash reveals a context menu with a “Put Back” option, which works as expected when selected.