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


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: 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 | # ]