Re: Save a file from textEdit - OS X
Re: Save a file from textEdit - OS X
- Subject: Re: Save a file from textEdit - OS X
- From: Hugh Dixon <email@hidden>
- Date: Tue, 20 Nov 2001 14:34:41 +0000
On 19/11/01 5:49 pm, Chris Prew of email@hidden wrote in whole or in
part:
>
Hi, I9m writing a script that creates a text file in TextEdit (OS X 10.1)
>
based on some user input. Then it saves the file to a directory that is also
>
based on the user input. I9ve used most variations of the save command I
>
can think of, but its not saving the file. Here it is:
>
>
set user_number to "0180"
>
>
tell application "TextEdit"
>
activate
>
close every document saving no
>
make new document at the beginning of documents
>
set the text of the front document to "Various text using " &
>
user_number
>
>
save the front document as "OS_X:docs:0180:newfile.txt"
>
close every document saving no
>
end tell
>
>
... but it
>
simply doesn9t get saved in the user directory that I want...
>
>
What am I doing wrong?
Hi,
According to its dictionary, the syntax for saving TextEdit files should be:
save front document in "OS_X:docs:0180:newfile.txt"
(Not "as").
But OMM (OSX 10.1.1, using a valid path) this saves a document called
"OS_X/docs/0180/newfile.txt" flat on my startup disk, and gives an error at
the same time. (And I can't see how to use the "as" paramater, which
supposedly specifies the file type.)
Two other approaches:
1) Use a text editor that saves files with better grace (Tex-Edit
Plus.Carbon, for example).
2) Use file write commands to create the file (which serendipitously will be
in TextEdit format). Watch for one long line:
set user_number to "0180"
set the_contents to "Various text using " & user_number
set new_file to (open for access file
("OS_X:docs:"&user_number&":newfile.txt") with write permission)
try
write the_contents to new_file
on error
close access new_file
end try
close access new_file
This has the added benefit of not flashing unnecessary windows.
HTH
Hugh
**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.
www.mimesweeper.com
**********************************************************************