Re: Textedit problems
Re: Textedit problems
- Subject: Re: Textedit problems
- From: Michael Terry <email@hidden>
- Date: Mon, 19 May 2003 11:28:57 -0700
On 5/19/03 8:45 AM, "Kris Hermans" <email@hidden> wrote:
>
Hi,
>
>
Anyone know how to copy a word from textedit.
>
This is what I have:
>
>
open aFile
>
tell application "TextEdit"
>
set deTekst to text of aFile
>
set allPars to every paragraph of deTekst
>
set AppleScript's text item delimiters to {"="}
>
repeat with i from 1 to (count allPars)
>
set aLine to paragraph i of deTekst
>
if text item 1 of aLine = "name=" then
>
copy text item 1 of aLine to Naam
>
end if
>
end repeat
>
set AppleScript's text item delimiters to {""}
>
end tell
>
>
It always returns an error " cannot get text of 'path to document' "
>
>
I want to check the text if there is a word that starts with "name" in it.
>
If so then I want to use the name to copy later in my filemaker database.
If you're going to use TextEdit to work with the file's text, then you need
to use the stuff in TextEdit's dictionary. You can't 'set deTekst to text of
aFile' because TextEdit doesn't know what that means. Instead, TextEdit
makes the text of a file available through its 'document' class. So,
tell application "TextEdit" to tell front document
set txt to every text
end tell
will put all the text of a document into a variable so you manipulate it
using plain AppleScript language features like text item delimiters and the
like. Or, you can leave the text in the document, and manipulate it using
the model provided by TextEdit's dictionary. Either way.
I'm not sure I know exactly what you're trying to do, but this
tell front document of application "TextEdit"
if "name=" is in every text then set Naam to "name="
end tell
will check the text of the front document and copy the word to a variable if
it's there.
An alternate way to get the text from a file is to use the 'read' Scripting
Addition command. You might look into it.
Mike
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.