I wish I had this feature 10 years ago!!! Thank you Gary for the detailed walkthrough. I can't wait to dive into more of your content and have more "ah ha" moments like this.
This man deserves an award. Thank you. I don't understand why Apple hasn't added this already. Another shortcut I made was a "New Script" shortcut, which does the same thing but runs a 'chmod +x' on the new file. This is useful for programmer types who need to make a quick script file (assuming they aren't in a terminal already, in which case it's quicker just to use the CLI).
The more of your videos I watch the more I'm loving the fact that I just bought a new Macbook. MacOS's shortcut functionality looks straight up linux-esq but far more user friendly for those not familiar with manually interop-ing bash and a scripting language like python. Can hardly wait for it to get here.
Good video as it shows scripts in shortcuts. When done with touch → it will be only .txt files, which is quite good. But sometimes you want a .rtf file, and there doesn't seem to be a solution for this, yet.
No. You'd need to create your version of a "blank" rtf file, put it somewhere, and then use shell scripts to duplicate that file. A lot more involved there.
I just toggle open iTerm2 with a keyboard shortcut (fn + F12) and type: touch file_1.txt file_2.txt file_3.txt or whatever. But this is still quite nifty 😀
The touch command does have a side effect when used with an existing file. Namely it changes the file’s modification date. If you don’t want that side effect to occur then the add an if statement to skip the touch command if the file already exists.
@@Thorz74 in the first example, enclose the touch command with an if statement that checks whether the file does not exist… if [ ! -e "$folder$name$extension" ] ; then touch "$folder$name$extension" fi
@@bevintx5440 Thanks a lot! That will be very useful. I'm wondering if the "fi" you put at the end line is just a typo, or is this part of the syntax?
Great video! I started to use Shortcuts thanks to your great tutorials. I was getting the error message "Error: Error: Can't get object." I finally understood why, it's because I was on the desktop and had no folder window opened. I rewatched the video and that's the first thing you said 😂
How about doing the same thing but with making a new folder or sub folder?? I think I’ve been doing the suggested the hard way🙃 Thanks for your suggestions and advice and support ❤️ your videos are site!!
You can't generate a new file. The best you can do is to have a template file you created and then make a Shortcut that duplicates that. But you can also just do that in the Finder with an Option+drag, or a Stationary file, or File, New in Word
Great.. makes me want to learn this.. by the way towed the end you said with "something" when something2 came up you said it will "append" ... is this adding to the list in the folder or taking the document and changing the first version to second .. Also once the doc file is there .. do I just select it and start writing ,, how do I use it?
@@macmost Yeah I felt bad because I just finished your video and its at the end. I just picked my Mac back up after being on windows for a good while, and it's crazy that this isn't a core feature. Thanks for making this video!
awesome video :) It would be nice, if you could suggest a solution for case when I need create different types of files, where I would like to select from suggested list like txt, JSON, js etc...
Excelent - Next time please start with the comment that you will leave link to download the scripts. I had to type it from scratch (better learning path) however it would be nice to do it in the fast path
A txt file is unique in that a new file is simply empty, 0 bytes. Any other type of new file, rtf included, would have some basic information in the file. So you can't just create a blank file and say it is an rtf file (or Pages, or Word, or Photoshop). You'll need to do a lot more work and actually have a blank file somewhere, then copy that blank file to the new location.
Also I added a File (path) and a 'Play sound' action at the end of the Shortcut. Also you cannot add another new text file (with the same name) to the same folder, as long as you don't first rename the first file, f ex from new.txt to new1.txt
It may work with .doc, but probably not other types. This creates a completely empty file and most apps will have some basic info in an "empty" file. Text files are the exception. But you could create a more complex script that copies a blank file you created previously to the new location and renames it.
Great video, exactly what I was looking for. What if Im not using finder and Im on the Desktop. Is there a way to use the shortcut and create the TXT in the desktop?
@@marcofulvio Can't try it right now, but I suppose if it isn't working for you then it isn't working. You could always open up a Finder window and go to the Desktop there.
I enjoy watching your videos and I truly appreciate the work you put into them and the quality thereof. On my new MacBook Air (Sonoma 14.1.1) I have coded this Shortcut, as shown, but it doesn't work: it does create new.txt, but it won't create new2.txt, etc. - it merely updates date/time on the (original) new.txt. Here is the code I copied from the video: if [ -e “$folder$name$extension” ] ; then i=2 while [ -e “$folder$name $i$extension” ] ; do let i++ done name=“$name $i” fi touch "$folder$name$extension" It seems apparent to me that the "if exists" statement does NOT work: it always returns a "false" value, no matter what, and the "touch" command is always executed. Please advise, and thanks in advance.
Hey Gary - great explainer! Just out of curiosity, what would be an everyday use case for needing to create a text file in a folder? Or is it simply just the lack of this functionality in MacOS vs Windows?
You may have a folder with images, screenshots or other files where you want add an explanatory note to it, with more information than the folder/ filename.
@@macmost great video, works really well! I had an old automator script but this is much better now. Though actually why stop at txt files, since most non-techie users typically use other formats. Is there any way to have it create new Pages, Keynote or Sheets documents? (I tried but couldn't manage to) Now that would REALLY save a lot of clicking 'Open app > New > Save as > Finder location > Name file > Save'
@@NerdSutra A txt file is the only kind of file that when new is just an empty 0-btye file. A file from an app, like Pages, would have lots of basic info in it (page size, font info, etc). Create a new Pages document with nothing in it, save it, and then try to look at it in a binary file editor. There's lots in there. So to create a "blank" Pages file you'd really need to start with a blank file that already exists, and duplicate it. But even that doesn't work for a lot of situations as you normally start with a template. Starting with the same template (like the Blank, Word Processing one) would work in some cases, but maybe not others. This is why the three apps you mentioned start a new document by prompting you for a template first.
@@macmost thanks for the breakdown 👍🏼🙂 It’s a pity there’s no Shortcut/scripting method on Mac to do it though. Sometimes you want to just get started quickly and save all these steps, that basically the app forces you to do, and it often breaks a chain of thought. It honestly should be an Apple-supplied service or action. These series of steps to simply start a new doc feel like a throwback to 1997!
Not sure what I am dong wrong @macmostvideo I keep getting an Error: Error : Can't get object. Please can someone guide me? I am using MacBook Pro 14 apple m3 chip, latest Mac OS as well.
Great video !!!! However I'm on Mac Sonoma Beta and it always comes back with "Operation not permitted". Arghhhhh. I'm guessing it's because I'm on a beta but if anyone has a solution please let me know as I would most appreciate it
I'm on Ventura and both script windows had the not permitted message. Underneath both of those windows, besides the message, was a link to allow. Once you allow on one window it allows on the other script window. At least that's what was available on my system. Hope it works for you.
Nice idea but you could do it in pure zsh by replacing the javascript with: folder=$(osascript -e 'tell application "Finder" to get the POSIX path of (target of front window as alias)')
Yes but then you are just calling AppleScript in zsh instead of JavaScript (same as AppleScript) beforehand. Plus it is great to learn how to pass info out of JavaScript/AppleScript and into a Shell script in Shortcuts. That opens up all sorts of possibilities.
@@jenningsfantini2675 First, you definitely want to mention that you are running early beta software when asking a question like this. But I also have macOS 15 beta on a Mac and I see "Run Javascript for Mac Automation" in Shortcuts.
folder="JavaScript Result" name="Provided Input" extension="${name##*.}" if [ "$extension" != "$name" ]; then extension=".$extension" else extension="" fi name="${name%.*}" if [ -e "$folder$name$extension" ] ; then i=2 while [ -e "$folder$name$i$extension" ] ; do let i++ done name="$name$i" fi touch "$folder$name$extension"
Lifetime Mac users usually don't see the need. But Windows users have been trained to create a new text file first, then open it. So they want that on their Mac too.
Very Useful !!! I been using automator script (similar) for a long time which served very well - but this one is good too 👍👍 Do you have a video on "How to use Mac as hotspot to transfer files on locally hotspot connected devices (ofcourse without internet)" - my router is very slow when transferring large files to other devices but my other laptop (Linux) is faster than my router - i was wondering if MacBook pro is any better for hotspot or FTP transfer large files ???
Lifetime Mac users usually don't see the need. But Windows users have been trained to create a new text file first, then open it. So they want that on their Mac too.
I wish I had this feature 10 years ago!!! Thank you Gary for the detailed walkthrough. I can't wait to dive into more of your content and have more "ah ha" moments like this.
This man deserves an award. Thank you. I don't understand why Apple hasn't added this already. Another shortcut I made was a "New Script" shortcut, which does the same thing but runs a 'chmod +x' on the new file. This is useful for programmer types who need to make a quick script file (assuming they aren't in a terminal already, in which case it's quicker just to use the CLI).
Wow thank you so much I have been looking for this!!! I am so used to Windows making everything so easy with right click features.
The more of your videos I watch the more I'm loving the fact that I just bought a new Macbook. MacOS's shortcut functionality looks straight up linux-esq but far more user friendly for those not familiar with manually interop-ing bash and a scripting language like python. Can hardly wait for it to get here.
A very useful and informative video tutorial today! Thank you, Gary! 👏🏻❤️
The man is a life saver ! Thank you big big !
Wow - so simple (not)!! Never the less, I shall put this into action, it's a very useful function...
This shows up JUST as I need it. Thank you!
Excellent Gary. A good intro. to the world of shortcuts.
Ouuuuu boy oh boy. This is very slick.
You're a good man. Thanks
Excellent and very useful! Just what I was looking for.
Very helpful shortcut. Thank you so much for providing this solution.
Good video as it shows scripts in shortcuts.
When done with touch → it will be only .txt files, which is quite good. But sometimes you want a .rtf file, and there doesn't seem to be a solution for this, yet.
No. You'd need to create your version of a "blank" rtf file, put it somewhere, and then use shell scripts to duplicate that file. A lot more involved there.
super helpful and well explained! Thank you!!
I just toggle open iTerm2 with a keyboard shortcut (fn + F12) and type:
touch file_1.txt file_2.txt file_3.txt
or whatever. But this is still quite nifty 😀
Very nice! You are a genius, Gary
Thank you very much!! Interesting and very detailed!!
amazing new things never seen before, thanks man
The touch command does have a side effect when used with an existing file. Namely it changes the file’s modification date. If you don’t want that side effect to occur then the add an if statement to skip the touch command if the file already exists.
Interesting. Can you (or anyone else) elaborate on how this is done? Thank you!
@@Thorz74 in the first example, enclose the touch command with an if statement that checks whether the file does not exist…
if [ ! -e "$folder$name$extension" ] ; then
touch "$folder$name$extension"
fi
Of course this “if” statement should not be added to the 2nd example, which uses versioning and hence already won’t “touch” an existing file.
@@bevintx5440 Thanks a lot! That will be very useful. I'm wondering if the "fi" you put at the end line is just a typo, or is this part of the syntax?
@@Thorz74 That “fi” is a reserved word and indicates the end of an “if” statement, when it is the first word and not quoted.
Great video! I started to use Shortcuts thanks to your great tutorials.
I was getting the error message "Error: Error: Can't get object." I finally understood why, it's because I was on the desktop and had no folder window opened. I rewatched the video and that's the first thing you said 😂
what can I do, if I want to create any file on desktop ?
Thanks for video that’s what I need 😉
Thanks Gary!
Great video, so useful.
Worked perfectly. Thanks. I was getting errors and it turns out they were typos on my part.
Awesome! Thanks
Thanks a lot Gary! Is it possible to make this work also in a folder on an external drive?
It should work there.
How about doing the same thing but with making a new folder or sub folder?? I think I’ve been doing the suggested the hard way🙃 Thanks for your suggestions and advice and support ❤️ your videos are site!!
Can we create shortcuts for generating new files for any of the MS Office apps? That would be very helpful.
You can't generate a new file. The best you can do is to have a template file you created and then make a Shortcut that duplicates that. But you can also just do that in the Finder with an Option+drag, or a Stationary file, or File, New in Word
Why it can't be easy like in Windows? Just right click of mouse + create new file with any extension you want (as I know it works min. 10 years)...
Great.. makes me want to learn this.. by the way towed the end you said with "something" when something2 came up you said it will "append" ... is this adding to the list in the folder or taking the document and changing the first version to second .. Also once the doc file is there .. do I just select it and start writing ,, how do I use it?
Great stuff
Superb.
Finally
I love you so much for this, but why not post the copy and paste script with the description or something?
I do. I post the whole Shortcut. 9:00
@@macmost Yeah I felt bad because I just finished your video and its at the end. I just picked my Mac back up after being on windows for a good while, and it's crazy that this isn't a core feature. Thanks for making this video!
awesome video :) It would be nice, if you could suggest a solution for case when I need create different types of files, where I would like to select from suggested list like txt, JSON, js etc...
You could add a menu to the Shortcut. But that would add steps. At some point it is just as easy to create the new files in the app you are using.
Excelent - Next time please start with the comment that you will leave link to download the scripts. I had to type it from scratch (better learning path) however it would be nice to do it in the fast path
Thank you for your shortcut But I wonder how to make RTF file cause If I change Extension as rtf, The file can't be opened
A txt file is unique in that a new file is simply empty, 0 bytes. Any other type of new file, rtf included, would have some basic information in the file. So you can't just create a blank file and say it is an rtf file (or Pages, or Word, or Photoshop). You'll need to do a lot more work and actually have a blank file somewhere, then copy that blank file to the new location.
@@macmost thanks every time 👍
Also I added a File (path) and a 'Play sound' action at the end of the Shortcut.
Also you cannot add another new text file (with the same name) to the same folder, as long as you don't first rename the first file, f ex from new.txt to new1.txt
Great. Loved it. Can we use this to create new .doc or .xls file as in windows?
It may work with .doc, but probably not other types. This creates a completely empty file and most apps will have some basic info in an "empty" file. Text files are the exception. But you could create a more complex script that copies a blank file you created previously to the new location and renames it.
Great video, exactly what I was looking for. What if Im not using finder and Im on the Desktop. Is there a way to use the shortcut and create the TXT in the desktop?
When you are using the Desktop you ARE using the Finder. You are in the Desktop folder. Just another way of viewing it.
@@macmost it doesnt work. Can you try on your end?
@@marcofulvio Can't try it right now, but I suppose if it isn't working for you then it isn't working. You could always open up a Finder window and go to the Desktop there.
When adding Ask for Input prompt, there's no checkbox for Allow Multiple Lines? I'm on Monterey.
That's because you are behind a version of macOS.
I enjoy watching your videos and I truly appreciate the work you put into them and the quality thereof.
On my new MacBook Air (Sonoma 14.1.1) I have coded this Shortcut, as shown, but it doesn't work: it does create new.txt, but it won't create new2.txt, etc. - it merely updates date/time on the (original) new.txt.
Here is the code I copied from the video:
if [ -e “$folder$name$extension” ] ; then
i=2
while [ -e “$folder$name $i$extension” ] ; do
let i++
done
name=“$name $i”
fi
touch "$folder$name$extension"
It seems apparent to me that the "if exists" statement does NOT work: it always returns a "false" value, no matter what, and the "touch" command is always executed.
Please advise, and thanks in advance.
Sorry, I don't know what could be wrong. Hard to debug code just with my eyes in a RUclips comment though. Keep working at it.
Hey Gary - great explainer! Just out of curiosity, what would be an everyday use case for needing to create a text file in a folder? Or is it simply just the lack of this functionality in MacOS vs Windows?
Just something Windows users learned to do.
You may have a folder with images, screenshots or other files where you want add an explanatory note to it, with more information than the folder/ filename.
@@macmost great video, works really well! I had an old automator script but this is much better now.
Though actually why stop at txt files, since most non-techie users typically use other formats.
Is there any way to have it create new Pages, Keynote or Sheets documents? (I tried but couldn't manage to)
Now that would REALLY save a lot of clicking 'Open app > New > Save as > Finder location > Name file > Save'
@@NerdSutra A txt file is the only kind of file that when new is just an empty 0-btye file. A file from an app, like Pages, would have lots of basic info in it (page size, font info, etc). Create a new Pages document with nothing in it, save it, and then try to look at it in a binary file editor. There's lots in there. So to create a "blank" Pages file you'd really need to start with a blank file that already exists, and duplicate it. But even that doesn't work for a lot of situations as you normally start with a template. Starting with the same template (like the Blank, Word Processing one) would work in some cases, but maybe not others. This is why the three apps you mentioned start a new document by prompting you for a template first.
@@macmost thanks for the breakdown 👍🏼🙂
It’s a pity there’s no Shortcut/scripting method on Mac to do it though.
Sometimes you want to just get started quickly and save all these steps, that basically the app forces you to do, and it often breaks a chain of thought.
It honestly should be an Apple-supplied service or action.
These series of steps to simply start a new doc feel like a throwback to 1997!
Thanks, can you put it in a writing it will help to create the function.
You can always download it from the link on the post at my site.
Any hope to get a shortcut to create a folder from selected elements? I feel it would be faster than right click.
Just use File, New Folder With Selection, which already has a keyboard shortcut.
how do I modify the shortcut so that I can input the "body" of the text file?
What are you trying to do exactly? Describe the situation.
Not sure what I am dong wrong @macmostvideo I keep getting an Error: Error : Can't get object.
Please can someone guide me? I am using MacBook Pro 14 apple m3 chip, latest Mac OS as well.
Just go through it and make sure you have everything set the same way, including the Details section. Start over again if you need to.
@@macmost Getting the same error. The issue seems to be with .url()
Great video !!!! However I'm on Mac Sonoma Beta and it always comes back with "Operation not permitted". Arghhhhh. I'm guessing it's because I'm on a beta but if anyone has a solution please let me know as I would most appreciate it
I'm on Ventura and both script windows had the not permitted message. Underneath both of those windows, besides the message, was a link to allow. Once you allow on one window it allows on the other script window. At least that's what was available on my system. Hope it works for you.
Can this be put in the right-click menu?
It can, but down in the Services submenu. You have that option in the Shortcut settings ("Services.")
@@macmost Doesn't seem to be working in Monterey 12.6.8
@@mikek3094 I’m showing this on Ventura
Nice idea but you could do it in pure zsh by replacing the javascript with: folder=$(osascript -e 'tell application "Finder" to get the POSIX path of (target of front window as alias)')
Yes but then you are just calling AppleScript in zsh instead of JavaScript (same as AppleScript) beforehand. Plus it is great to learn how to pass info out of JavaScript/AppleScript and into a Shell script in Shortcuts. That opens up all sorts of possibilities.
I don't have the `Run Javascript for Mac Automation` option...?
Make sure you are looking in the right place -- exactly where I show it in the video.
I am looking exactly there and have turned on a setting to allow script running. I think it is a bug in macOS 15. I can only run shell scripts
@@jenningsfantini2675 First, you definitely want to mention that you are running early beta software when asking a question like this. But I also have macOS 15 beta on a Mac and I see "Run Javascript for Mac Automation" in Shortcuts.
@@macmost hmmm that’s interesting. Will try rebooting and cleaning system caches.
@@macmost nothing yet. I filed some feeback
folder="JavaScript Result"
name="Provided Input"
extension="${name##*.}"
if [ "$extension" != "$name" ]; then
extension=".$extension"
else
extension=""
fi
name="${name%.*}"
if [ -e "$folder$name$extension" ] ; then
i=2
while [ -e "$folder$name$i$extension" ] ; do
let i++
done
name="$name$i"
fi
touch "$folder$name$extension"
I am getng permission denied issue
What does the error say exactly?
It would be good if the text file were opened immediately and text from the clipboard was inserted.
You can do that! It would just take a few more actions...
Hmm, call it a failure of imagination on my part, but I don't understand where you would use this? I don't understand the purpose of it.
Lifetime Mac users usually don't see the need. But Windows users have been trained to create a new text file first, then open it. So they want that on their Mac too.
The fact that we need to do this ourselves show how dumb mac os is sometimes.
So ridiculously complicated for such a simple task. Isn't creating a text file supposed to be a one-click action?
That's the idea. This Shortcut allows you to make it on-action thing.
Very Useful !!!
I been using automator script (similar) for a long time which served very well - but this one is good too 👍👍
Do you have a video on "How to use Mac as hotspot to transfer files on locally hotspot connected devices (ofcourse without internet)" - my router is very slow when transferring large files to other devices but my other laptop (Linux) is faster than my router - i was wondering if MacBook pro is any better for hotspot or FTP transfer large files ???
Your router should be the fastest way to do that. If it is very old, maybe consider getting a new one. They are pretty cheap.
Why??
Lifetime Mac users usually don't see the need. But Windows users have been trained to create a new text file first, then open it. So they want that on their Mac too.