Re: Textedit problems
Re: Textedit problems
- Subject: Re: Textedit problems
- From: Andrew Oliver <email@hidden>
- Date: Mon, 19 May 2003 09:44:33 -0700
Is there a reason why you're using TextEdit at all? AppleScript can read and
process text files on its own, without any application's involvement.
set filecontents to read file "path:to:file" using delimiters {return}
-- filecontents is now a list with one line/paragraph per list item
set nameLines to every item of filecontents whose contents begins with
"name="
-- now 'nameLines' is a list of all the lines that begin with 'name='.
-- We can iterate through them to process them one by one.
repeat with aLine in nameLines
-- Normally I'd use text item delimiters to break the line, but
-- since you know each line begins with the same part, it's easier to:
set Naam to characters 6 through -1 of aLine
-- now 'Naam' contains the portion of text after the 'name='
-- do with it what you will.
end repeat
BTW, this line:
>
set AppleScript's text item delimiters to {""}
Is dangerous. You don't know that the text item delimiters were null/empty
string before your script started. It's always better to save the current
delimiters and restore them later (arguments of 'AppleScript's' vs. 'my'
notwithstanding).
Andrew
:)
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.
>
>
Apparently the first step already doesn't work, so...
>
>
Can someone please help me
>
>
Thanks
>
_______________________________________________
>
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.
_______________________________________________
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.