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

Поделиться
HTML-код
  • Опубликовано: 22 авг 2024

Комментарии • 107

  • @hopeful_labrat
    @hopeful_labrat 8 месяцев назад +2

    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.

  • @filthyE
    @filthyE 6 месяцев назад

    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).

  • @jaypolarbear
    @jaypolarbear 7 дней назад

    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.

  • @fmwyt95
    @fmwyt95 Год назад +1

    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.

  • @loisskiathitis8926
    @loisskiathitis8926 Год назад +2

    A very useful and informative video tutorial today! Thank you, Gary! 👏🏻❤️

  • @zacknazarov1649
    @zacknazarov1649 6 месяцев назад +1

    The man is a life saver ! Thank you big big !

  • @joelonsdale
    @joelonsdale Год назад +3

    Wow - so simple (not)!! Never the less, I shall put this into action, it's a very useful function...

  • @theamericandanceinstitute8143
    @theamericandanceinstitute8143 3 месяца назад

    This shows up JUST as I need it. Thank you!

  • @wonkywombat
    @wonkywombat Год назад

    Excellent Gary. A good intro. to the world of shortcuts.

  • @kingyertle100
    @kingyertle100 Год назад +1

    Ouuuuu boy oh boy. This is very slick.

  • @Greg-fg1rd
    @Greg-fg1rd Год назад +1

    You're a good man. Thanks

  • @ccx3-3658
    @ccx3-3658 10 месяцев назад

    Excellent and very useful! Just what I was looking for.

  • @ChristianLouwPedersen
    @ChristianLouwPedersen Год назад

    Very helpful shortcut. Thank you so much for providing this solution.

  • @omarkn4371
    @omarkn4371 Год назад +2

    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.

    • @macmost
      @macmost  Год назад +3

      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.

  • @rogermeyers4815
    @rogermeyers4815 9 месяцев назад

    super helpful and well explained! Thank you!!

  • @gregf9160
    @gregf9160 Год назад +1

    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 😀

  • @ThierryLalinne
    @ThierryLalinne Год назад

    Very nice! You are a genius, Gary

  • @martrom0
    @martrom0 11 месяцев назад

    Thank you very much!! Interesting and very detailed!!

  • @AppFanUAE
    @AppFanUAE Год назад

    amazing new things never seen before, thanks man

  • @bevintx5440
    @bevintx5440 Год назад +4

    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
      @Thorz74 4 месяца назад

      Interesting. Can you (or anyone else) elaborate on how this is done? Thank you!

    • @bevintx5440
      @bevintx5440 4 месяца назад +1

      @@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
      @bevintx5440 4 месяца назад

      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.

    • @Thorz74
      @Thorz74 4 месяца назад

      ​@@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?

    • @bevintx5440
      @bevintx5440 4 месяца назад

      @@Thorz74 That “fi” is a reserved word and indicates the end of an “if” statement, when it is the first word and not quoted.

  • @isabellegiguere1121
    @isabellegiguere1121 Год назад

    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 😂

    • @manikantagangam8916
      @manikantagangam8916 8 месяцев назад

      what can I do, if I want to create any file on desktop ?

  • @user-ti9mv9hb3g
    @user-ti9mv9hb3g 7 месяцев назад

    Thanks for video that’s what I need 😉

  • @beatkellermusic
    @beatkellermusic Год назад

    Thanks Gary!

  • @mahmood1212
    @mahmood1212 Год назад

    Great video, so useful.

  • @DergEnterprises
    @DergEnterprises 5 месяцев назад

    Worked perfectly. Thanks. I was getting errors and it turns out they were typos on my part.

  • @harryhellerman474
    @harryhellerman474 Год назад

    Awesome! Thanks

  • @beatkellermusic
    @beatkellermusic 3 месяца назад

    Thanks a lot Gary! Is it possible to make this work also in a folder on an external drive?

    • @macmost
      @macmost  3 месяца назад

      It should work there.

  • @larrysimassr7492
    @larrysimassr7492 Год назад

    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!!

  • @gurjotsinghsidhu1643
    @gurjotsinghsidhu1643 4 месяца назад

    Can we create shortcuts for generating new files for any of the MS Office apps? That would be very helpful.

    • @macmost
      @macmost  4 месяца назад

      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

  • @krzysztofeko4
    @krzysztofeko4 11 месяцев назад +3

    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)...

  • @davidpatrick1813
    @davidpatrick1813 Год назад

    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?

  • @mrfrano100
    @mrfrano100 Год назад

    Great stuff

  • @accentontheoff
    @accentontheoff Год назад

    Superb.

  • @mcgyverhadouken930
    @mcgyverhadouken930 Год назад +1

    Finally

  • @AHWD
    @AHWD 4 месяца назад

    I love you so much for this, but why not post the copy and paste script with the description or something?

    • @macmost
      @macmost  4 месяца назад +1

      I do. I post the whole Shortcut. 9:00

    • @AHWD
      @AHWD 4 месяца назад

      @@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!

  • @serhiivozniuk393
    @serhiivozniuk393 Год назад

    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...

    • @macmost
      @macmost  Год назад

      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.

  • @ezrakoper
    @ezrakoper 10 месяцев назад

    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

  • @HJ-su7px
    @HJ-su7px 6 месяцев назад

    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

    • @macmost
      @macmost  6 месяцев назад

      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.

    • @HJ-su7px
      @HJ-su7px 6 месяцев назад

      @@macmost thanks every time 👍

  • @omarkn4371
    @omarkn4371 Год назад

    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

  • @mukulaur
    @mukulaur Год назад

    Great. Loved it. Can we use this to create new .doc or .xls file as in windows?

    • @macmost
      @macmost  Год назад

      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.

  • @marcofulvio
    @marcofulvio 11 месяцев назад

    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?

    • @macmost
      @macmost  11 месяцев назад

      When you are using the Desktop you ARE using the Finder. You are in the Desktop folder. Just another way of viewing it.

    • @marcofulvio
      @marcofulvio 11 месяцев назад

      @@macmost it doesnt work. Can you try on your end?

    • @macmost
      @macmost  11 месяцев назад

      @@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.

  • @alienrefugee51
    @alienrefugee51 Год назад

    When adding Ask for Input prompt, there's no checkbox for Allow Multiple Lines? I'm on Monterey.

    • @macmost
      @macmost  Год назад

      That's because you are behind a version of macOS.

  • @stevenfullbright5900
    @stevenfullbright5900 9 месяцев назад

    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.

    • @macmost
      @macmost  9 месяцев назад

      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.

  • @plaherne79
    @plaherne79 Год назад

    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?

    • @macmost
      @macmost  Год назад

      Just something Windows users learned to do.

    • @omarkn4371
      @omarkn4371 Год назад

      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.

    • @NerdSutra
      @NerdSutra 8 месяцев назад

      @@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'

    • @macmost
      @macmost  8 месяцев назад

      @@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.

    • @NerdSutra
      @NerdSutra 8 месяцев назад

      @@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!

  • @avnerbenzvi8757
    @avnerbenzvi8757 11 месяцев назад

    Thanks, can you put it in a writing it will help to create the function.

    • @macmost
      @macmost  11 месяцев назад

      You can always download it from the link on the post at my site.

  • @lock_
    @lock_ Год назад

    Any hope to get a shortcut to create a folder from selected elements? I feel it would be faster than right click.

    • @macmost
      @macmost  Год назад

      Just use File, New Folder With Selection, which already has a keyboard shortcut.

  • @nukki2869
    @nukki2869 5 месяцев назад

    how do I modify the shortcut so that I can input the "body" of the text file?

    • @macmost
      @macmost  5 месяцев назад

      What are you trying to do exactly? Describe the situation.

  • @shahjahanravjee8639
    @shahjahanravjee8639 3 месяца назад

    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.

    • @macmost
      @macmost  3 месяца назад

      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.

    • @ai_snippets
      @ai_snippets 2 месяца назад

      @@macmost Getting the same error. The issue seems to be with .url()

  • @MrMitchfromtoronto
    @MrMitchfromtoronto Год назад

    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

    • @rawsaxy
      @rawsaxy Год назад

      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.

  • @mikek3094
    @mikek3094 Год назад

    Can this be put in the right-click menu?

    • @macmost
      @macmost  Год назад +1

      It can, but down in the Services submenu. You have that option in the Shortcut settings ("Services.")

    • @mikek3094
      @mikek3094 Год назад

      @@macmost Doesn't seem to be working in Monterey 12.6.8

    • @macmost
      @macmost  Год назад

      @@mikek3094 I’m showing this on Ventura

  • @AlanClements
    @AlanClements 10 месяцев назад

    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)')

    • @macmost
      @macmost  10 месяцев назад

      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.

  • @humblfinance1043
    @humblfinance1043 2 месяца назад

    I don't have the `Run Javascript for Mac Automation` option...?

    • @macmost
      @macmost  2 месяца назад +1

      Make sure you are looking in the right place -- exactly where I show it in the video.

    • @jenningsfantini2675
      @jenningsfantini2675 2 месяца назад

      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

    • @macmost
      @macmost  2 месяца назад

      @@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.

    • @jenningsfantini2675
      @jenningsfantini2675 2 месяца назад

      @@macmost hmmm that’s interesting. Will try rebooting and cleaning system caches.

    • @humblfinance1043
      @humblfinance1043 2 месяца назад

      @@macmost nothing yet. I filed some feeback

  • @uoidqwt
    @uoidqwt 4 месяца назад +1

    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"

  • @muneebmukhthar4880
    @muneebmukhthar4880 3 месяца назад

    I am getng permission denied issue

    • @macmost
      @macmost  3 месяца назад

      What does the error say exactly?

  • @macfritz899
    @macfritz899 Год назад

    It would be good if the text file were opened immediately and text from the clipboard was inserted.

    • @macmost
      @macmost  Год назад +2

      You can do that! It would just take a few more actions...

  • @SoNowWhat
    @SoNowWhat Год назад

    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.

    • @macmost
      @macmost  Год назад +1

      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.

  • @user-gy9sv7fp3i
    @user-gy9sv7fp3i 22 дня назад

    The fact that we need to do this ourselves show how dumb mac os is sometimes.

  • @Paglov
    @Paglov 11 месяцев назад

    So ridiculously complicated for such a simple task. Isn't creating a text file supposed to be a one-click action?

    • @macmost
      @macmost  11 месяцев назад

      That's the idea. This Shortcut allows you to make it on-action thing.

  • @garrysingh4484
    @garrysingh4484 Год назад

    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 ???

    • @macmost
      @macmost  Год назад

      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.

  • @holelabsllc668
    @holelabsllc668 Год назад

    Why??

    • @macmost
      @macmost  Год назад +2

      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.