Re: Error-trapping alias properties
Re: Error-trapping alias properties
- Subject: Re: Error-trapping alias properties
- From: Kai Edwards <email@hidden>
- Date: Fri, 29 Mar 2002 11:56:42 +0000
on Wed, 27 Mar 2002 23:13:17 -0800, Paul Berkowitz <email@hidden>
wrote:
>
Is there a way to error-trap alias objects saved as script properties, in
>
case the file has been trashed and emptied or the script moved to another
>
computer?
(snip)
>
Can you store an alias as a script property, and still find a graceful way
>
to set a new value (via choose file again, e.g.) if the file no longer
>
exists?
>
>
I know that storing the string file path to the file wouldn't hit this
>
problem, but then it would throw up an error , or dialog if trapped, every
>
time the file is moved or renamed. Is there some way around this?
There just may be, Paul.
I suspect the key to sneaking through the front door could be to initially
avoid a head-on 'confrontation' with the stored alias.
Instead, you may be able to use a reference to the alias, coerce that to a
string - and then perform a few text-based routines before testing for the
existence of the alias itself.
Anyway, the approach seems to work reasonably well for me so, with suitable
modification, I hope it may help you a little too.
The following script is peculiar to my system and would obviously need
revising for use elsewhere. (My deleted trash files, for example, end up in
a TechTool Pro Cache.)
-----------------------------------------------------------
property origFile : ""
property trashCache : alias "Macintosh HD:oTP2o TrashCache:"
on run
set theFile to a reference to origFile as string
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
else
set origFile to choose file
end if
end run
to check(thePath)
set {tid, text item delimiters} to {text item delimiters, ":"}
set folderPath to (thePath's text 1 thru text item -2 & ":")
set text item delimiters to tid
try
set theFolder to folderPath as alias
on error
err("Could not locate \"" & folderPath & "\"")
end try
if theFolder = (path to trash folder as alias) then
err("The file is in the trash.")
else if theFolder = trashCache then
err("The file has been deleted.")
end if
end check
on err(msg)
beep
display dialog msg buttons "Cancel" default button 1 with icon 0
end err
-----------------------------------------------------------
HTH
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.