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.
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.
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.. 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 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.
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.
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 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 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.
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
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.
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.
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
@@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!
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
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!!
@@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.
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.
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.
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...
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.
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 😂
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.
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!
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 ???
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).