• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
re: Strange problem with text item delimiters
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

re: Strange problem with text item delimiters


  • Subject: re: Strange problem with text item delimiters
  • From: Kai <email@hidden>
  • Date: Fri, 04 Jul 2003 06:32:13 +0100

on Wed, 2 Jul 2003 16:56:45 -0600, David Crowe wrote:

> Kai;
>
> I tried the little scriptlet you sent:
>
> set AFile to "afilename.doc" as Unicode text
> set text item delimiters to "."
> set ParsedFilename to AFile's text items
> ParsedFilename
> --> {"afilename", "doc"}
>
>
> ... and it produced the correct result.

- which serves to support my contention that the behaviour of your original
script is not attributable (in this case) to Unicode text.

> After a little more playing around, I discovered that my script
> breaks when I attempt to get the text items of (name of aFile), e.g.:

Exactly. That's what I was referring to when I said:

>> ...'text items' needs to act on *text*...

and

>> ...the object being considered (name of alias "XYZ") had clearly
>> not been evaluated as text before the attempt to extract its
>> text items...

- so the result is likely to be a broken script (manifested in one way or
another).

> set text item delimiters to "."
> tell application "Finder"
> set aRandomFile to first file of startup disk
> set ParsedFilename to text items of (name of aRandomFile)
> set x to (name of aRandomFile)
> end tell
> class of (name of aRandomFile) & class of x
> --> {property, Unicode text}
>
> So, why is class of (name of aRandomFile) "property" and not "Unicode
> text", even though if you copy (name of aRandomFile) to a variable,
> the variable's class is "Unicode text"?

Because (name of aRandomFile) has not yet been evaluated - as I suggested
when I said:

>> the partial result was a reference to <name of alias "XYZ">
>> rather than a text value

In other words, I don't think you can rely on the automatic evaluation of
composite statements - especially if they mix AppleScript expressions and
application objects.

For example, this doesn't work for me:

-------------------------

tell application "Finder" to set x to [NO BREAK]
words of name of first folder of first disk

-------------------------

In such cases, its evidently necessary to evaluate separately - either by
discrete step[1], explicit coercion[2] or (as Marc and JD demonstrated) the
'get' command[3]:

-----------[1]-----------

tell application "Finder" to set x to name of first folder of first disk
set x to words of x

-----------[2]-----------

tell application "Finder" to set x to [NO BREAK]
words of (name of first folder of first disk as string)

-----------[3]-----------

tell application "Finder" to set x to [NO BREAK]
words of (get name of first folder of first disk)

-------------------------

> It seems like something is wrong here, but for now at least I have a
> workaround.

The principle isn't dissimilar to another behaviour that can sometimes cause
confusion:

-------------------------

set myCat to "jaguar"
set catList to {"lion", "tiger", "jaguar", "panther"}
repeat with cat in catList
if cat is myCat then display dialog "Found the " & myCat & "!"
end repeat

--> [no result]

-------------------------

The result (or lack of it) might seem initially perplexing, until the
comparison values in the relevant repeat are identified as:

-------------------------

{myCat, cat}

--> {"jaguar", item 3 of {"lion", "tiger", "jaguar", "panther"}}

-------------------------

So 'cat' is not equal to 'myCat' because the reference <item 3 of {"lion",
"tiger", "jaguar", "panther"}> has not yet been evaluated as "jaguar".

In this case, the value of 'cat' can similarly be obtained by step[1],
coercion[2] or the 'contents' property of the reference[3]:

-----------[1]-----------

set myCat to "lion"
set catList to {"lion", "tiger", "jaguar", "panther"}
repeat with catNum from 1 to count catList
set cat to catList's item catNum
if cat is myCat then display dialog "Found the " & myCat & "!"
end repeat

--> "Found the lion!"

-----------[2]-----------

set myCat to "tiger"
set catList to {"lion", "tiger", "jaguar", "panther"}
repeat with cat in catList
if cat as string is myCat then [NO BREAK]
display dialog "Found the " & myCat & "!"
end repeat

--> "Found the tiger!"

-----------[3]-----------

set myCat to "panther"
set catList to {"lion", "tiger", "jaguar", "panther"}
repeat with cat in catList
if cat's contents is myCat then [NO BREAK]
display dialog "Found the " & myCat & "!"
end repeat

--> "Found the panther!"

-------------------------

--
Kai
_______________________________________________
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.

  • Prev by Date: Re: why won't force-eject work in a script, but will from command line?
  • Next by Date: Moving IMAP messages in Entourage
  • Previous by thread: re: Strange problem with text item delimiters
  • Next by thread: Strange problem with text item delimiters
  • Index(es):
    • Date
    • Thread