By John Gruber
WorkOS: APIs to ship SSO, SCIM, FGA, and User Management in minutes. Check out their launch week.
So I saw this post on TUAW about NuFile, a contextual menu plugin that gives you a shortcut to create new files in the Finder using the contextual menu.
I thought that sounded pretty cool, but I’d only ever use it for creating text files. So I wrote an AppleScript for Brent Simmons’s freeware Big Cat Scripts Plugin that does just that. Here’s how to use it:
If you haven’t done so already, download and install Big Cat Scripts.
Copy the script below, paste it into your script editor, and save it in your ~/Library/Application Support/Big Cat Scripts/Files/. I named my script “New Text File”.
Control-click in any Finder window and choose your script from the Scripts sub-menu.
A dialog box will appear, prompting you for a file name. Enter a name, then click Create.
The file will be created and opened for editing in your preferred text editor. (See below.)
Here’s the script:
on main()
tell application "Finder"
try
set _folder to (the target of the front window) as alias
on error
beep
end try
display dialog ¬
"New text file name:" default answer "" buttons ¬
{"Cancel", "Create"} default button 2
set _fname to text returned of result
if exists file _fname of _folder then
display alert "A file named ‘" & _fname & ¬
"’ already exists in this folder." as informational
return -- ends script
end if
set _path to quoted form of ((POSIX path of _folder) & _fname)
do shell script "bbedit " & _path
end tell
end main
The do shell script
line at the end of the script assumes that your favorite text editor has a command-line tool, and that the tool is available in your shell’s PATH
. If you use TextWrangler, change the “bbedit
” tool to “edit
”; if you use TextMate, change it to “mate
”; and if you use SubEthaEdit, change it to “see
”.