Re: Help with scripting text editor with comments from file?
Re: Help with scripting text editor with comments from file?
- Subject: Re: Help with scripting text editor with comments from file?
- From: Michelle Steiner <email@hidden>
- Date: Tue, 6 Mar 2001 09:15:58 -0800
On 3/6/01 7:17 AM, T.J. Mahaffey <email@hidden> wrote:
>
Can anyone tell me what I'm doing wrong here?
>
I'm trying to create a droplet that will perform the following on the items
>
dropped on it:
>
>
Create a text file, name it the same as the file's name, set the text of the
>
file to the text from the file's comment window, and save the file to the
>
HD. I'm using Tex-Edit Plus, but any insight you folks could give will apply
>
to most any small text editor like it.
You don't need to use an application to create the document; Applescript
can do that for you directly. Also, your script puts the file in the
disk's folder; it might be better to put it in a designated folder, or in
the folder containing the file. However, if the latter is done, then it
can't have the same name as the original file; since I chose this method,
I opted to append ".cmt" to the file name. This brings up another
problem: to wit that the resulting file name might be more than 31
characters in length, so I tested and truncated if necessary.
I also put in code to remark that an item has no comments, if that's the
case, but since you didn't ask for that, I commented it out.
Here's the result:
on open (itemList)
repeat with thisItem in the itemList
tell application "Finder"
set itemName to name of thisItem
set itemComment to comment of thisItem
set itempath to container of thisItem as text
end tell
(*
if itemComment is "" then
set itemComment to "This item has no comments."
end if
*)
if (count itemName) is greater than 27 then
set itemName to text 1 through 27 of itemName
end if
set NewfileName to itemName & ".cmt"
set itemRef to open for access file ,
(itempath & NewfileName) with write permission
try
write itemComment to itemRef
close access itemRef
on error
close access itemRef
end try
end repeat
end open
--Michelle
----------------------------------------------------------------------
| Michelle Steiner | We're not human beings having a spiritual |
| | experience. We're spiritual beings |
| email@hidden | having a human experience. |
----------------------------------------------------------------------