Create empty text file in current Finder folder? Possibly also enter current date into it. "readme.txt"

I'd like to be able to create a readme.txt in my current Finder folder if a file of that name doesn't exist there.

My second phase would probably be open the file in BBEdit and type "[CurrentDate] [MyName]: " in the file if the file didn't already exist when I ran the macro.

If I were doing this interactively (which is a hassle), I'd use Typinator to type in the current date. So Typinator could be part of the solution, but that's not a requirement.

Update: I used > and < around some variable names and they showed blank here in Discourse. Sorry about that. I replaced them with ] and [.

Based on your somewhat loose description, here's a simple macro that creates a readme.txt file in the currently-open Finder folder if one doesn't already exist. If it creates that file then the macro also puts the current date into it. If the file already exists the macro does nothing.

Download Macro(s): Test Create Readme File.kmmacros (2.9 KB)

Macro-Image

Keyboard Maestro Export

Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System Information
  • macOS 10.14.6
  • Keyboard Maestro v10.2
5 Likes

Here is what I've been using for years in addition to @tiffle's solution:

(It will not do any short date naming.)

In an Execute an AppleScript action:

try
   
   set fileName to "README.txt"
   
   tell application "Finder"
      set insertionLocationPath to insertion location as alias
      make new file at insertionLocationPath with properties {name:fileName}
   end tell
   
   set fullFilePath to ((insertionLocationPath as text) & fileName) as alias
   
   tell application "TextEdit"
      activate
      open fullFilePath
   end tell
   
on error e number n
   set e to e & return & return & "Num: " & n
   if n ≠ -128 then
      try
         tell application (path to frontmost application as text) to set ddButton to button returned of ¬
            (display dialog e with title "ERROR!" buttons {"Copy Error Message", "Cancel", "OK"} ¬
               default button "OK" giving up after 30)
         if ddButton = "Copy Error Message" then set the clipboard to e
      end try
   end if
end try
1 Like

That is exactly what I wanted, but which I didn't know how to express in Keyboard Maestro. Thank you!

1 Like

Thank you so much! Nice!

Well I took a bit of a guess but that's great to hear!

If it solves your problem please mark my post as the solution so future forum visitors can immediately see the result. Thanks!

1 Like

@tiffle has you covered with a user friendly KM-centric macro, but here's one using the shell – just for fun.


Download: Create a ReadMe File in the Front Finder Window v1.00.kmmacros (5.7 KB)

Macro-Image

Keyboard Maestro Export

Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.

System Information
  • macOS 10.14.6
  • Keyboard Maestro v10.2

1 Like

Thank you. Nice!

1 Like