• Welcome to MUGOO Message Board.
 

News:

Many thanks to Dan Millar for creating our board logo, the "mapple"! 
To go to the main MUGOO website, click the big banner above ...

Main Menu

Tip : create "new text file" in Finder

Started by z-mac, April 11, 2007, 11:53:24 PM

Previous topic - Next topic

z-mac

Redmondows doesn't get ~everything~ wrong, and one feature that I like is the pop-up menu that enables the user to create New->Folder and New->File. In OS X, you have New->Folder but not New->File.

Here's how to have New->File functionality in the OS X Finder.

Right click in Finder.
Click Automator->Create Workflow.
Select "Automator" in the Library pane, under Applications.
In Automator, close the dialog in the rightmost frame so you only see the label, "Drag or add actions here..."
In the Action pane, select Run Applescript.
Drag Run Applescript into the rightmost pane.
Delete all the code in the Run Applescript window.
Paste the code below into the window. Change the code as desired.
When ready, select File>Save As A Plug In (for Finder).

To run the script, you right-click in a folder in the Finder, then select Automator. The name of the new plug-in should appear in the pop-up menu.

(AppleScript to paste...)

property max : "99"
property type : "txt"
set fname to "new-file."

tell application "Finder"
   try
      get target of front Finder window
   on error
      get desktop
   end try
   set thisFolder to result
   
   try
      make new file at thisFolder with properties {name:fname & type}
      return result as alias
   end try
   
   repeat with i from 2 to max
      try
         make new file at thisFolder with properties {name:(fname & i & "." & type)}
         return result as alias
         exit repeat
      on error errorMsg number errorNum
         if (i is equal to (max as integer)) or (errorNum is not -48) then
            display alert "Error (" & errorNum & ")" message errorMsg as warning buttons "Cancel"
            exit repeat
            return missing value
         end if
      end try
   end repeat
end tell


z-mac

Here's a small improvement to select the file that is created.

property max : "99"
property type : "txt"
set fname to "new-file."

tell application "Finder"
   try
      get target of front Finder window
   on error
      get desktop
   end try
   set thisFolder to result
   
   try
      make new file at thisFolder with properties {name:fname & type}
      select result
      return result as alias
   end try
   
   repeat with i from 2 to max
      try
         make new file at thisFolder with properties {name:(fname & i & "." & type)}
         select result
         return result as alias
         exit repeat
      on error errorMsg number errorNum
         if (i is equal to (max as integer)) or (errorNum is not -48) then
            display alert "Error (" & errorNum & ")" message errorMsg as warning buttons "Cancel"
            exit repeat
            return missing value
         end if
      end try
   end repeat
end tell