Re: Strange problem with text item delimiters
Re: Strange problem with text item delimiters
- Subject: Re: Strange problem with text item delimiters
- From: Kai <email@hidden>
- Date: Sat, 28 Jun 2003 17:12:29 +0100
on Fri, 27 Jun 2003 17:57:06 -0400, "Marc K. Myers" wrote:
>
> Date: Fri, 27 Jun 2003 10:35:39 -0400
>
> From: David Crowe <email@hidden>
>
>
>
> I had the following code:
>
>
>
> tell application "Finder"
>
> -- set variable 'aFile' to an alias
>
> set AppleScript's text item delimiters to "."
>
> set ParsedFilename to text items of (name of aFile)
>
> ...
>
> end
FWIW, I tried this in OS 9.1 and got an error:
--> Finder got an error: Can't get every text item of name of alias
"Macintosh HD:Desktop Folder:Test File.sit".
This didn't particularly surprise me, since we're asking AS to coerce an
alias (rather than a string) to a list. In other words, we're relying an
automatic coercion from alias to string before the string-to-list coercion.
>
> This code worked, and then suddenly stopped working, producing a null
>
> list given a string like "afilename.doc" (not even a list with a
>
> single item).
>
>
>
> I replaced the code with:
>
>
>
> set AppleScript's text item delimiters to "."
>
> set x to (name of aFile)
>
> set ParsedFilename to text items of (x as string)
>
>
>
> ... and it started working again.
It should be possible to shorten the line 'set ParsedFilename to text items
of (x as string)' to 'set ParsedFilename to text items of x' - because x is
already a string.
It's also worth noting Emmanuel's point about Unicode text - since some
systems can do this:
--==============================================
set AppleScript's text item delimiters to {""}
("flying about" as Unicode text)'s text items as string
--> "lying about"
--==============================================
>
> Can anyone explain what happened? I'm using OSX with Smile as the
>
> editor, but the code is executed via FileMaker.
>
>
>
> (I mean, I'm happy that I've found a workaround, but I really don't
>
> like mysteries like this).
>
>
The problem is not with the TIDs. The name property of the variable
>
aFile didn't get resolved. It works this way, too:
>
>
tell application "Finder"
>
-- set variable 'aFile' to an alias
>
set AppleScript's text item delimiters to "."
>
set ParsedFilename to text items of (get name of aFile)
>
>
I don't understand why it happens but it seems to happen pretty
>
frequently. By putting in the explicit "get" it is forced to resolve
>
before the rest of the statement gets processed.
I suppose a couple of pieces of advice mentioned here from time to time
(set, use - and then restore tids asap / put only essential statements into
a tell block), might help us avoid some of these pitfalls:
--========================
set aFile to choose file
tell application "Finder" to set aFile to aFile's name
set AppleScript's text item delimiters to "."
set ParsedFilename to aFile's text items
set AppleScript's text item delimiters to {""}
ParsedFilename
--========================
...but looking at some of my code examples, I'm a fine one to talk. ;-)
At the end of the day, what strikes me most is how code that used to error
now seems to (silently) produce erroneous results. I'm tempted to assume
it's a bug.
--
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.