Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Easily save TextEdit documents via AppleScript Apps
I often dump ideas, questions, and answers in TextEdit files which I later use Spotlight to retrieve. Saving lots of these files manually is a chore, so I created an AppleScript to take care of this.

How it works is it takes the first paragraph (a line followed by return) of the document -- typically the title in my writing -- and uses this to name the text file (note some characters like ':' cannot be used in file names), and then saves the text file in your Documents folder. Here's the script: [robg adds: To use the script, save it to your user's Library » Scripts » Applications » TextEdit folder (in 10.5), and you can then access it from the Scripts menu within TextEdit. I tested it, and it works as described.]
    •    
  • Currently 2.75 / 5
  You rated: 2 / 5 (8 votes cast)
 
[22,956 views]  

Easily save TextEdit documents via AppleScript | 6 comments | Create New Account
Click here to return to the 'Easily save TextEdit documents via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Easily save TextEdit documents via AppleScript
Authored by: piyayo on Sep 22, '08 01:34:18PM

Thanks. I found this very useful. I also figured out long ago that the best way to keep notes is the finder and spotlight, and it's better than any note keeping app, at least for me.



[ Reply to This | # ]
Easily save TextEdit documents via AppleScript
Authored by: Michael_S on Sep 23, '08 11:53:06AM
I thought so too, but using a note-keeping app helps to keep all these in one place, so you don't have to worry about where to look. It's also faster to summon than using AppleScript. But by far the biggest advantage of a good dedicated app is sync across several computers.

I can recommend Smultron (payment requested) or Yojimbo (commerical), which also has good provisions to store serial numbers, passwords, etc..

Regards, Michael

[ Reply to This | # ]

Easily save TextEdit documents via AppleScript
Authored by: PizzaCake on Sep 23, '08 01:52:08AM

Glad you liked it. However I personally don't use the script menu for this script. I pasted the script into script editor and saved as application. I've got this app on my dock which I click to save the foremost textedit document.

I've slightly modified it to work with Pages. Instead of the first line it uses the header of the document to name the file.

tell application "Pages"
set headerText to odd header of section 1 of document 1
set documentName to headerText
end tell

tell application "Finder"
set theDocumentPath to (path to documents folder as string) & (documentName as string) & ".pages"
if item (theDocumentPath) exists then -- check if document already exists, avoid overwriting it!
display alert "Document already exists!"
else
try
tell application "Pages" to save document 1 in theDocumentPath
on error
display alert "Cannot save " & theDocumentPath as text
end try
end if
tell application "Pages" to activate
end tell


Or combine the two scripts as:

set Btn to button returned of (display dialog "Which Application Document would you like to save?" buttons {"Cancel", "Pages", "TextEdit"} default button "TextEdit" with icon 1)

if Btn is "TextEdit" then

tell application "TextEdit"
set documentName to ""
set paragraphText to paragraph 1 of document 1
if (count of paragraphs of document 1) = 1 then
set documentName to paragraphText
else
-- get rid of newline character
set documentName to ((characters 1 thru -2 of paragraphText) as text)
end if
end tell

tell application "Finder"
set theDocumentPath to (path to documents folder as text) & (documentName as text) & ".rtfd" as text
if item (theDocumentPath) exists then -- check if document already exists, avoid overwriting it!
display alert "Document already exists!"
else
try
tell application "TextEdit" to save document 1 in theDocumentPath
on error
display alert "Cannot save " & theDocumentPath as text
end try
end if
tell application "TextEdit" to activate
end tell

end if

if Btn is "Pages" then

tell application "Pages"
set headerText to odd header of section 1 of document 1
set documentName to headerText
end tell

tell application "Finder"
set theDocumentPath to (path to documents folder as string) & (documentName as string) & ".pages"
if item (theDocumentPath) exists then -- check if document already exists, avoid overwriting it!
display alert "Document already exists!"
else
try
tell application "Pages" to save document 1 in theDocumentPath
on error
display alert "Cannot save " & theDocumentPath as text
end try
end if
tell application "Pages" to activate
end tell

end if



[ Reply to This | # ]
Easily save TextEdit documents via AppleScript
Authored by: grasshoppermouse on Sep 23, '08 04:09:18AM
I do something similar. Here is my solution:

1. Cut and paste the following script into Script Editor:


set note_name to text returned of (display dialog "New note name:" default answer "")
if note_name is not "" then
	tell application "Finder"
		set the_folder to ((folder of the front window) as alias)
		set the_file to make new file at the_folder with properties {name:(note_name & ".txt")}
		open the_file
	end tell
end if

2. Using Script Editor, save it as an application to ~/Library/Scripts. When saving, be sure and de-select the "Startup screen" option.

3. Drag the icon of the compiled app to the toolbar of the Finder window. Wait a second or two until you see the "+", and then release. The functionality of this script is now available in every Finder window.

4. Optionally create a folder named "Notes" -- mine is inside my Documents folder. Drag this folder to the sidebar of the Finder. This folder will now be accessible in any Finder window.

To use, simply click the icon in the Finder toolbar and a small dialog box will open asking for a file name. Provide one, and a text file will be created in whatever folder you are currently viewing and then opened in your default text editor (probably Text Edit). To create a new note in your Notes folder, first click on the folder icon in the sidebar.

Use spotlight to find your notes.

[ Reply to This | # ]

Easily save TextEdit documents via AppleScript
Authored by: qprfact on Oct 22, '08 08:49:58AM

This hint looks like it will solve my issue, but perhaps someone can confirm?

I use an Applescript to take lyrics from iTunes and convert to TextEdit files.

If I select multiple music files, it produces multiple TextEdit files on my desktop - all good. I then want to save them all, but they need to be "Saved as", which takes time (a lot of it!)

Will this script save all the TextEdit files created under the Artist - Track Title format that appears in the title bar of the window?



[ Reply to This | # ]
Easily save TextEdit documents via AppleScript
Authored by: BluesPower on Jan 17, '10 11:52:49PM

Can someone help me.

I wanted a script which can save the text file into today's folder. And when I am creating a text file tomorrow it should automatically save the file into tomorrows folder. The folders are already created. I am using Mac OS X Snow Leopard.

Thanks in advance.
Murali



[ Reply to This | # ]