Re: Handler joy (or the Joy of Reference forms)
Re: Handler joy (or the Joy of Reference forms)
- Subject: Re: Handler joy (or the Joy of Reference forms)
- From: Richard 23 <email@hidden>
- Date: Tue, 27 Feb 2001 23:46:32 -0800
>
> Why am I having this problem?
>
>
>
> if I run this line outside of the handler
>
>
>
> get the number of items of ProcessedFolder
>
>
>
> (where ProcessedFolder is the alias "Hard Disk:Desktop Folder:Test
>
> II:Masters:Processed:")
>
> everything works fine and it returns the # of items inside the Processed
>
> folder. Even if there is nothing in the folder (what I want) But if I simply
>
> place this line inside a handler and send it the ProcessedFolder alias like
>
> this...
>
>
>
> on CheckProcessed (pFolder)
>
> get the number of items of pFolder
>
> end CheckProcessed
>
>
>
> It gives me an error "Can't get every item of alias "Hard Disk:Desktop
>
> Folder:Test II:Masters:Processed:"
>
> ???
>
>
>
> What am I missing?
The Jolly one replied:
>
Not sure. This works fine for me:
>
>
property ProcessedFolder : "Mac HD:"
>
>
return my CheckProcessed(ProcessedFolder)
>
>
on CheckProcessed(pFolder)
>
get the number of items of pFolder
>
end CheckProcessed
must be an Addition JR...AppleScript doesn't do that.
First "Mac HD:" is being coerced to a file spec or alias for you,
and second something sneaky is using the File Manager behind the
scenes to get your result. AppleScript does neither of these.
AppleScript doesn't know much about files by itself.
The Finder specializes in such things.
I imagine you've found these roadblocks:
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
set theAlias to alias "Private:Utilities:"
-- OR --
tell application "Finder" to set theAlias to ==>
alias "Private:Utilities:"
get items of theAlias
--> Can't get every item of alias "Private:Utilities:".
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
These do work:
set theAlias to alias "Private:Utilities:"
tell application "Finder" to return items of theAlias
return items of item theAlias of application "Finder"
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
You can even use a variable to represent the application if
you're using generic terminology, but sometimes it requires
more careful wording:
set Finder to application "Finder"
get items of Finder's theAlias
--> Finder got an error: Invalid key form.
These work:
get items of Finder's item theAlias
tell Finder to get items of theAlias
So does this little trick I use when I want to write to
a file that was accidentally left open:
tell {duplicate, delete} of file logPath of Finder to ==>
set first item's name to last item's name
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
You can also use "a reference to" which will give you the
result you were expecting from your CheckProcessed handler.
part of the reference is the application itself so that when
you query a variable containing such a reference you are in
fact querying the application itself.
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
set folderPath to "Private:Applications:"
set theRef to a reference to Finder's alias folderPath
get result's items
set theRef to a reference to theRef's items
tell theRef to get {name, name of items}
-- "name of items" may fetch a pretty big list
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Finally applying the last method to your handler:
set Finder to application "Finder"
set pFolder to "Private:Applications:"
set theRef to a reference to Finder's item pFolder
CheckProcessed(theRef)
--> 9
on CheckProcessed(pFolder)
get the number of items of pFolder
end CheckProcessed
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Hopefully that's more than enough reference forms to
get you well on your way...
R23