Many Mac users wish there was a way to create a new text file in the Finder just like you can in Windows. With the help of a simple Automator service you can add this to your Mac, and even customize how it works.
You can also watch this video at YouTube (but with ads).
Here is the code from the first Run JavaScript action:
function run(input, parameters) { var finder = Application('Finder'); finder.includeStandardAdditions = true; var currentPath = decodeURI(finder.windows[0].target().url().slice(7)); return currentPath; }
Is it possible to populate the new text file with the contents of the clipboard?
Greg: Sure. Instead of the JavaScript code that returns "", use the Automator Get Contents of Clipboard action.
Thanks for this. I've been looking for a way to dip my toe into Automator and this perfectly meets my need to create a new text entry every day. With this start, I'm going to explore on my own, finding a way to add the current date to my file name. The teaching method and examples really help me. Being a Patron to your channel is the best money I spend every month.
Hi Gary, very timely —use Text Edit a lotduring every day mainly to save snippets. This would be extremely useful.
Followed your instructions meticulously, however when I ran it got this error message: 'The action “Run JavaScript” encountered an error: “Error: Error: Can't get object.”
Any clues as to what I'm doing. wrong?
Bill: Hard to say where you may be going wrong. Make sure all of the parts of the Automator workflow are like mine, including ins and outs of the various parts.
I'm also getting this error - ‘The action “Run JavaScript” encountered an error: “Error: Error: Can’t get object.”
I went through the process twice, not sure if I'm doing something wrong, any ideas?
Andre: See my note to Bill above.
Great job as always Gary. I really like these automation posts. Just wanted to provide this supportive note of your efforts.
This is great Gary. It worked for me. I was wondering for a long time how to do this on MacOS. On Wndows there is an entry already on the context menu, you right click, select "New" and then select "Text Document". It would also be nice to have this on the context menu in a "Finder" window.
Thank Gary, I really look forward to your Automator tutorials.
On this occasion I believe you've been trumped by an app called 'New Text File', which costs pennies and genuinely fills the gap for us ex-Windows users. Unobtrusive and just the right number of options.
Definitely one for your Top of the Apps...
Hi Gary!
When I try to run it, i get this message
"Error on line 9: Syntax error: Return statements are only valid inside functions"
I'm not too great with Automator, can you help?
Robert
Robert: Hard too say without seeing it. Carefully compare what you have with what you see in the video. Pay special attention to every detail to spot any differences.
In response to errors, First, the first time you run the it after boot, you have to be in an open Finder location AND use the Finder> Services >New Text file method. You also have tube at a place in Finder where you can actually create a new text document. For example, if you're just on the desktop or another application's window, you'll get an error message. After that OK to use f-key assigned. Error also if you already have file with name in same place. Will not add new text file(1). Thanks.
Is there anyway to convert this (or other) workflows into an app? I have found the mini-apps for addressing and sending and email (from a tutorial you posted many moons ago) very useful, easy, reliable and portable. To create and open a new text file would be great for this. I tried a copy and paste into an "app" in automator but, of course, got nowhere. Thanks for considering this for a future tutorial.
Bart: You can make it an app, but you have to deal with the change of input. Where will this file be created? An app isn't being run "in" a location like a Quick Action. You could set it up so it asks for a location, or you drag and drop a folder onto the app to have it get the location, but those extra steps make it less useful. So I think this particular workflow works better as a Quick Action, not an app.