Create shortcut for new .txt (or any) file in OSX

Aaron Medina
3 min readMay 3, 2018

PART I. CREATE AN APPLE SCRIPT VIA AUTOMATOR

Step 1. Open Automator application.

Step 2. Create new Service.

Step 3. Set Service receives selected to no input.

Step 4. Drag the Run AppleScript action in the workflow area.

Step 5. Delete the default content and paste the code below:

on run {input, parameters}try    tell application "Finder" to set the thisFolder to (folder of the front window) as aliason error -- if no folder is open in finder or focused in running application, set default location to desktop    set the thisFolder to path to desktop folderend tryset fileName to text returned of (display dialog "Create new .txt file named:" default answer "Textfile.txt")
set filePath to POSIX path of thisFolder
set theFile to filePath & fileName
set prefixString to "copy of "
-- if filename already existing, this service will ask for a new filename
tell application "Finder"
repeat while exists file theFile as POSIX file set fileName to text returned of (display dialog "\"" & fileName & "\" already exists, please provide another name:" default answer prefixString & "Textfile.txt")
set theFile to filePath & fileName
set prefixString to prefixString & "copy of "
end repeat
end telldo shell script "touch \"" & theFile & "\""return input
end run

Step 6: Save AppleScript as CreateNewTextFile (or any other desired name).

STEP 7: Close Automator.

PART II. SET UP KEYBOARD SHORTCUT FOR THE NEW SERVICE

Step 1: Search Keyboard in Spotlight.

Step 2: Open Shortcuts tab.

Step 3: Select Services from left panel.

Step 4: Look for General item.

Step 5: Assign keyboard shortcut by selecting CreateNewTextFile service and click Add Shortcut button.

Step 6: Assign desired keyboard shortcut.

Step 7: Close System Preferences.

Step 8: Test by pressing your keyboard shortcut.

--

--