Being able to create plain text files easily anywhere in Finder helps with using the iCloud-backed native file system for personal knowledge management. It's my preferred alternative to third-party apps whose longevity may be uncertain.
- Open Automator.
- From Library, choose "Utilities", then "Run AppleScript" action.
- At the top of the workflow window, you'll see a few dropdown menus. Set the first one ("Workflow receives current") to "files or folders", and the second one to "Finder".
- Paste the following AppleScript code:
on run {input, parameters}
set thePath to POSIX path of (first item of input as text)
if (thePath does not end with "/") then
set thePath to thePath & "/"
end if
set fileName to "untitled"
set fileExtension to "txt"
set counter to 1
set theFile to thePath & fileName & "." & fileExtension
tell application "Finder"
repeat
try
if exists (POSIX file theFile) then
set counter to counter + 1
set theFile to thePath & fileName & " " & counter & "." & fileExtension
else
exit repeat
end if
on error
exit repeat
end try
end repeat
end tell
do shell script "touch \"" & theFile & "\""
delay 0.1
set hfsPath to POSIX file theFile as text
tell application "Finder"
activate
select file hfsPath
end tell
delay 0.1
tell application "System Events"
keystroke return
end tell
return input
end run
Save the workflow: Go to File > Save and give your service a name, like "New Text File".
Now, when you right-click on a folder in Finder, you should see the option "New Text File" at the bottom of the context menu, in the 'Quick Actions' submenu.
- Open "System Preferences".
- Click on "Keyboard".
- Choose the "Shortcuts" tab.
- In the list on the left, select "Services" or "Quick Actions" (depends on your macOS version).
- Scroll down to find your script under the "Files and Folders" section. It should have the same name as you saved it in Automator.
- Click on the "Add Shortcut" button or the area to the right of the script name, then press the key combination you want to use as the shortcut. Be sure to choose a shortcut that doesn't conflict with any other shortcuts used by Finder or any other apps.
- Restart Finder: option-right-click on the Finder icon in the Dock and select "Relaunch".