Re: Error-trapping alias properties
Re: Error-trapping alias properties
- Subject: Re: Error-trapping alias properties
- From: Kai Edwards <email@hidden>
- Date: Sat, 30 Mar 2002 04:01:05 +0000
on Fri, 29 Mar 2002 07:14:06 -0800, Paul Berkowitz <email@hidden>
wrote:
>
On 3/29/02 3:56 AM, "Kai Edwards" <email@hidden> wrote:
>
>
> if theFile is not "" then
>
> check(theFile) -- do any required text-based checks and continue
>
> try
>
> get theFile as alias -- or whatever
>
> on error
>
> set origFile to choose file -- or whatever
>
> end try
>
>
Thanks for trying Kai. But won't that bit of code make you 'choose file' all
>
over again any time you move the file from one folder to another? I can get
>
that by simply storing the string file path, and is precisely what I'm
>
trying to avoid.
Actually, it won't here, Paul - although I think I've done enough checking
of my suggestion to rule it out for another reason. Nevertheless, I found
the rechecking process did offer a few more clues...
>
Your method still sets origFile to an alias (the result of 'choose file'),
>
and that's what you're storing in the property. So it does not avoid the
>
head-on confrontation: the script will never get to your error test when it
>
hits 'property : origFile' right at the op of the script, on a different
>
computer.
I'm not convinced that the errors in these scripts are thrown at the point
where a property is declared, right at the top of the script. It looks to me
as though they occur the first time a broken alias property is directly
referred to in a running script.
That is to say:
property someFile : "" -- no error here, where the property is declared
if someFile is "" then -- error here, where it is evaluated
After a little reflection, I've had another look at this - and, while the
use of 'a reference to' does apparently skirt around the problem, it seems
to do so in a flawed way. Here's my reasoning:
If the value of the property 'someFile' is:
alias "HD:Desktop Folder:Test"
- then the following results are returned OMM - when the file referred to no
longer exists:
someFile = ""
--> error
- because 'someFile' is a broken alias which can't be resolved
a reference to someFile as string = ""
--> false
- because the string reference is "HD:Desktop Folder:Test"
So the use of 'a reference to', combined with a string coercion, would seem
to successfully avoid evaluation of the alias itself.
However, if there's no evaluation of the alias, then what we're probably
looking at is an string coercion from the alias - the *last* time it was
evaluated. That is, before it got broken. (We'd still then need a try block
to attempt a resolution of the alias.)
So it seems this approach only really tells us the file path at the time the
alias was last evaluated.
But since it avoided the error that <someFile = ""> couldn't avoid, it
fooled me into thinking I'd cracked the problem. >-(
>
The reason why you're avoiding it when you trash the file must be the same
>
as what Emmanuel and Paul Skinner found: the script somehow "imagines" a
>
hard disk whose name is a conflation of the saved startup disk plus root
>
folder and doesn't error it. Peculiar and faulty as this is, it would
>
actually be good enough to get all our error tests past that first barred
>
door, if it were consistent. But it doesn't work, in my experience on both
>
OS 9 and X, if you move the script to another computer.
Yeah. I never really have a problem with the trashed items anyway. I did,
however, encounter trouble if I moved the script to another machine - until
I tried using 'a reference to'.
>
As soon as I can make the time, I'll play around with these things and see
>
if there's some way to fool the system past the first line.
I'm still pretty sure the trick is to avoid confronting any evaluation of
the property directly. My only problem here is that, OMM, coercing an empty
string to an alias returns an alias path to the script's parent folder.
So I had to resort to something like this:
-----------------------------------------------
property someFile : ""
set myFolder to getFolder(path to me as string)
try
set fileTest to someFile as alias
if fileTest = myFolder then error
on error
set someFile to choose file
end try
--do other checks (trash, etc.)
to getFolder(thePath)
set {tid, text item delimiters} to {text item delimiters, ":"}
set theFolder to thePath's text 1 thru text item -2
set text item delimiters to tid
theFolder as alias
end getFolder
-----------------------------------------------
>
Thanks to those who tested with trashed files. I'm still wondering why those
>
false startup disks with conflated names make it past the front door of the
>
alias property.
As ever, the plot thickens. ;-)
Kai
--
**********************************
Kai Edwards Creative Resources
1 Compton Avenue Brighton UK
Telephone +44 (0)1273 326810
**********************************
_______________________________________________
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.