AppleScript for Creating a Text File in the Current Finder Directory
by hzimmerman in Circuits > Apple
11239 Views, 11 Favorites, 0 Comments
AppleScript for Creating a Text File in the Current Finder Directory
You know the situation: in OSX you simply want to create a quick textfile in your current Finder folder (dare I mention the Desktop?). AppleScript comes to the rescue!
Add the AppleScript Icon to the OSX Menu Bar
Inside the AppleScript editor (in your OSX Applications - Utilities) go to Preferences - General and check
[x] Show Script menu in menu bar
Add This Script to Your User Scripts
-- H.Zimmerman, AppleScript.
-- Create text file in current Finder folder with a dialog.
tell application "Finder"
try
display dialog "name of doc please (without the .txt thing)" default answer ""
set fileName to the text returned of result
if length of fileName = 0 then
return 0
end if
set fileExt to ".txt"
set thisFolder to the target of the front window as alias
set newFile to fileName & fileExt
make new file at thisFolder with properties {name:newFile, file type:"TEXT", creator type:"ttxt"}
on error errMsg
display dialog (errMsg)
end try
end tellMake a Text File
In the appropriate Finder folder, simply select the menu item you just added, type a name and your file is there. Double clicking it will open the familiar Text Edit.