Use a Shortcut To Create a New Text File In a Folder On a Mac

There is no command in the Finder that will let you create a new blank file at your current location. But you can create a Shortcut that will let you do this each time easily. The Shortcut needs to use both JavaScript and shell scripting to get the job done.



Link to the Shortcut.

Comments: 24 Responses to “Use a Shortcut To Create a New Text File In a Folder On a Mac”

    Jacques Du Biel
    1 month ago

    Hi Gary,
    I just tried this shortcut, and when I run it it errors out on the decodeURI javascript call with a "Error: Error: Can't get object.". Am I missing something?
    Thanks

    1 month ago

    Jacques: Make sure you are following along with everything and using it exactly as I am.

    Roger
    1 month ago

    I added the Ask for Input and now get this error message: folder=/Users/rogermas/Documents/Testfolder/: Command not found.
    name=New: Command not found.
    extension=.txt: Command not found.
    folder: Undefined variable.

    1 month ago

    Roger: All I can suggest is to start over and check everything carefully. I can't debug it for you from afar.

    Bill Toney
    1 month ago

    Instead of a Text File, would this work in opening other file designations. Would this be as simple as changing .txt in the Shortcut to .xlsx to create a new Excel file?

    Roddy
    1 month ago

    Gary, I appreciate all you've contributed throughout the years. I've learned so much since I first started using Macs in the 1980s! I always recommend to those I help with their Apple computer/tech questions to go watch your tutorials.

    I added the Input text prompt to the shortcut script link you've posted as stated in the video. I'm on Ventura, and at first, the two script windows within Shortcuts didn't have permission to run, but a simple click on the message enabled it.

    1 month ago

    Bill: No. Plain text files are unique in that an empty one is simply a completely empty zero-bytes-long file. Other apps create "empty" files that are very different from that.

    Elliot Kaufman
    1 month ago

    I tried Bill Toney's workaround for Word, Excel, Photoshop and Keynote files. The modified shortcut created a new.*** file for all of these. However, only the .docx Word file was able to be opened by its host application. All of the others were not seen as files that could be opened.

    Sheldon Hough
    1 month ago

    And...thanks bunches...I did not know one could comment at your site instead of YouTube....

    Joe
    1 month ago

    Hi Gary, I slightly modify this shortcut to make a small script to copy and paste onto terminal for a ffmpeg audio conversion, but I am having problems when there are empty spaces in the finder folder, if the finder folder does not have empty spaces in the name it works but if it does have, terminal throw an error "No such file or directory"
    Also how can I make shell script to make ffmpeg conversions directly? Thank you

    1 month ago

    Joe: When writing Shell scripts, you need to enclose paths with spaces in quotes, or escape the spaces with a \ like My\ Folder\ Name.

    Brian Oxley
    1 month ago

    Hi Gary - this shortcut would be a Godsend for me. I can't find where to download it. Could you post a link. Sorry if it is staring me in the face!!

    1 month ago

    Brian: Look under the video and above the comments for the "Link to the Shortcut."

    Mike
    1 month ago

    I downloaded the Shortcut and tried adding the 'Ask For Text' prompt per the video. But when I run the Shortcut, I can't type into the prompt. I'm using macOS Monterey 12.6.8. Please advise. Thanks.

    1 month ago

    Mike: Monterey is going to be different, for sure. But you should still be able to type in it. Can you click in the field and then type?

    Mike
    1 month ago

    Hi Gary. No, I'm not able to click in the prompt and type. I was able to right-click and paste into it, but no typing.

    1 month ago

    Mike: No explanation for that. Try a restart and see if it persists.

    Steve
    1 month ago

    Can you add one more line to open the new.text file with TextEdit?

    1 month ago

    Steve: Yes. just repeat the last line but replace touch with open.

    Ken Nellis
    1 month ago

    Great shortcut! I shall be playing with that. I often miss that Windows feature. I would call adding the name option as gilding the lily, and be happy with "untitled.txt", but the missing feature for me is that the shortcut should also auto-select the file in the Finder. Then it can be immediately opened.

    Ken Nellis
    1 month ago

    Thanx, works great! It would be great if it would work on the Desktop. (Currently complains with an error message.)

    Avner Ben Zvi
    1 month ago

    Dear Gary,

    there is any option to download the script ??

    Thanks

    1 month ago

    Avner: Yes. There is a link below the video.

    Tom Theiring
    1 month ago

    You're amazing, Gary! This is exactly what I've been needing! Many thanks!!

Leave a New Comment Related to "Use a Shortcut To Create a New Text File In a Folder On a Mac"

:
:
:
0/500 (500 character limit -- please state your comment succinctly and do not try to get around this limit by posting two comments)