The usual routine is: open a text editor, hit Save, then hunt through the save dialog for the folder that was already open in front of you. Or switch to Terminal, cd into the right place, and touch it.
Snippety can combine that into a single snippet.
The snippet
Create a snippet with a single Command Line Script placeholder:
{@script|TextField|touch "$(osascript -e 'tell application "Finder" to POSIX path of (target of front window as alias)')%@.txt"|NO@}
Give it a name you will remember, something like New File, and that is the whole setup.
What the command actually does
Three pieces, from the inside out:
osascript -e 'tell application "Finder" to POSIX path of (target of front window as alias)'asks Finder which folder its frontmost window is showing, and returns it as a normal path like/Users/you/Projects/.$( ... )drops that path into the string, so whatever you type gets appended to it.touchcreates an empty file at the resulting path.
The two parameters around the script matter as much as the script itself. The input mode is TextField, which is what makes Snippety stop and ask you for the file name when you expand the snippet. Escaping is set to NO, because %@ already sits inside a quoted string; leaving escaping on would wrap it in a second set of quotes and put them in the file name. Names with spaces still work fine.
One thing worth knowing: touch prints nothing, so the snippet expands to an empty string. Nothing is typed into the app you triggered it from. You can fire it from your editor, your browser, or Slack, and the only visible result is a new file appearing in Finder.
Standalone version: works as is
If you use the standalone build of Snippety, paste the snippet in and you are done. The app is not sandboxed, so it can talk to Finder and write to any folder you have access to.
App Store version: install Snippety Helper first
The App Store build is sandboxed, and that changes things. Sandboxed apps can only write inside ~/Downloads, and they cannot send Apple Events to Finder. Both halves of this snippet need exactly what the sandbox blocks, so it will fail on its own.
The fix is Snippety Helper, a small background script that runs commands outside the sandbox and hands the output back. Install it from Terminal:
cd ~/Downloads && /bin/bash -c "$(curl -fsSL https://snippety.app/SnippetyHelper-Installer.sh)"
Then start it, and set it to launch at login if you want the snippet to keep working after a restart. The documentation covers both the Automator route and a Launch Agent.
With the helper running, wrap the command in snippety-helper. The quoting has to flip around, since the outer argument now takes the single quotes:
{@script|TextField|snippety-helper 'touch "$(osascript -e "tell application \"Finder\" to POSIX path of (target of front window as alias)")%@.txt"'|NO@}
Same behaviour, one extra moving part. If you would rather not run a background helper, the standalone build is the simpler answer.
Variations
Once the pattern is there, the rest is just editing the command:
- A different extension. Change
.txtto.md,.sh, or drop it entirely and type the extension yourself. - Open it right away. Chain the two commands so the file opens in your default editor as soon as it exists:
{@script|TextField|bash -c 'f="$(osascript -e '\''tell application "Finder" to POSIX path of (target of front window as alias)'\'' )%@.txt"; touch "$f"; open "$f"'|NO@}
The Command Line Script placeholder is the general-purpose escape hatch in Snippety: anything you can do in a shell, you can bind to a keyword. Creating a file is just the smallest useful example. See the placeholder reference for what else it composes with, or Snippety for developers for more in this direction.
Ready to type less and do more?
Snippety is a native text expander for Mac, iPhone, and iPad. Free to start — one-time purchase available.