Categories
Productivity

Touch a folder or file in macOS Finder

Touch is a unix utility for Linux and macOS that updates the modified and access timestamps on a file.

In macOS Finder and Windows File Explorer I typically sort my files by Date Modified in reverse order, to put the most recently used files on top. This makes it easier to find stuff I am working on now, but some of those files aren’t modified and don’t move to the top. Touch can take care of that, but there is no built-in touch integration in Finder.

But it can be done in Automator.

Automator

Launch Automator from the Launchpad. Automator will present you with an Open dialog. Select “New Document”.

Automator will present you with a new document.

In the “Choose a type for your document” modal select “Quick Action” and “Choose”.

The modal will close and you can now edit the document. In “Workflow receives current” select “files or folders”. Next to “in” select “Finder.app”. You can also change the Image or Color to suite your tastes, but they are not necessary.

Now you need to add an Action. Scroll down to “Run Shell Script” and drag the action into the workflow builder.

Now you need to customize the Run Shell Script action. I left Shell at /bin/zsh (Catalina default), but you can change it to your favorite. In “Pass input” select “as arguments”.

With the last selection, Automator adds a template script to the script editor.

for f in “$@”
do
echo “$f”
done

In the editor change “echo” to “touch”.

You are now ready to save the Automator document. In the “File” menu select “Save…” or type ⌘S. In “Save quick action as” enter “Touch”. Then select “Save”.

The file is saved in $HOME/Library/Services as “Touch.workflow”, and appears in System Preferences Extensions.

In Finder the Touch menu now appears in the Actions menu.