Reading a File (Was: Re: TextEdit and Text Item Delimiters)
Reading a File (Was: Re: TextEdit and Text Item Delimiters)
- Subject: Reading a File (Was: Re: TextEdit and Text Item Delimiters)
- From: email@hidden
- Date: Wed, 31 Jul 2002 17:17:12 -0700
Okay, I'm trying a different (and, I think, better) tack.
I'm going to use the script additions to read the file directly. This
actually looks to be easier in the long run, as I can more easily specify
delimiters.
However, given the TextEdit file:
-----------------------
command=Share
folder="Disk:Folder:"
as="Name"
-----------------------
and running it through the script:
set pairs to read fileRef using delimiters {"=",return}
log pairs
I get ALMOST what I expect, but it has two garbage characters at the very
beginning (what looks like a backwards comma, and a flipped-upside-down
carrot). I could do:
set pairs to read fileRef from 2 using delimiters {"=",return}
but I don't think that the garbage will be there every time. Will it? Any
idea what it is?
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Seth A. Roby
Scriptwriter Intern
"Life is like an exploded clown. It's really funny until you figure out
what just happened."
Christopher Nebel
<email@hidden To: email@hidden
m> cc: email@hidden
Subject: Re: TextEdit and Text Item Delimiters
07/31/2002 03:58
PM
On Wednesday, July 31, 2002, at 03:36 PM, email@hidden wrote:
>
But now I'm trying:
>
tell app "TextEdit" to set allText to the text of document 1
>
>
set keepSafe to AppleScript's text item delimiters
>
set AppleScript's text item delimiters to {"="}
>
set keyParagraph to first paragraph whose first text item is "foo"
>
>
And the last line gives me the same error... I think this is because
>
you can't use a filter reference on a list, only on containers (which
>
is the most annoying part of AS I've found so far).
Oh. Heh. Should have looked at your script a bit more carefully before
suggesting that particular tack. AppleScript knows about both "text
item" and "paragraph", but, as you realized, doesn't support the filter
form (aka "whose") on any built-in types like strings or lists. I agree
that it's very annoying.
As an alternate path, you might try returning to the all-TextEdit
version, but try using "word n" instead of "text item n". Given your
data so far, they amount to the same thing, but won't if you start
throwing in spaces. Failing that, it's always possible to emulate
"whose" expressions using explicit loops. It's a pain and you shouldn't
have to, but it does work.
--Chris Nebel
AppleScript Engineering
_______________________________________________
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.