• 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: Error-trapping alias properties
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Error-trapping alias properties


  • Subject: Re: Error-trapping alias properties
  • From: Steven Angier <email@hidden>
  • Date: Sat, 30 Mar 2002 23:11:43 +1100

Why not just do something like:

prop gFile:{}

try
if gFile = {} then error
set gFile to gFile as string as alias
on error
set gFile to choose file
end


Or, using the Macscript.com Library, you could use:

prop gFile:{}

if not VerifyFile(gFile) then set gFile to choose file


Steven Angier
Macscript.com



On 30/3/02 4:53 PM, "Paul Berkowitz" <email@hidden> wrote:

> On 3/29/02 3:56 AM, "Kai Edwards" <email@hidden> wrote:
>
>>> 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.
>
> Paul,
>
> This is it! It works, with suitable tests, both when the file is trashed,
> and when moving the script to another computer. The peculiar thing, as Kai
> discovered first, is that trashing the file results in the alias (and a
> coercion to string as well) appearing as the initial path at when it was
> first set (why is that, I wonder?). Even odder, it happens with an explicit
> 'get' as well:
>
> property fileRef : ""
>
> if fileRef = "" then
> set theFile to choose file
> set fileRef to a reference to theFile
> display dialog "OK! All set up"
> return
> else
>
> try
> set theFile to contents of fileRef
> get theFile
> on error
> display dialog "You trashed the file."
> set theFile to choose file
> set fileRef to a reference to theFile
> end try
>
> display dialog (theFile as string)
>
> end if
>
> ---------
>
> That does indeed get past the 'property block'. But it still gives the
> initial path in the display dialog at the end, rather than erroring with
> "You trashed the file".
>
> However, as Emmanuel said, 'fully resolving' by FIRST coercing the alias to
> string, then trying to coerce the string back to an alias, is what work:
>
> try
> set theFile to contents of fileRef
> set filePath to theFile as string
> get alias filePath
> on error
> display dialog "You trashed the file."
> set theFile to choose file
> set fileRef to a reference to theFile
> end try
>
>
> That, at last, results in "You trashed the file" both on the same computer
> and also when moving the script to another computer, both in OS 10.1.3 and
> 9.2.2 (AS 1.8.2b3 on both).
>
> Thanks to all who contributed. A successful conclusion.
_______________________________________________
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.

References: 
 >Re: Error-trapping alias properties (From: Paul Berkowitz <email@hidden>)

  • Prev by Date: Re: Quickie Question
  • Next by Date: Internet Connect scripting enhancement
  • Previous by thread: Re: Error-trapping alias properties
  • Next by thread: Re: Error-trapping alias properties
  • Index(es):
    • Date
    • Thread