• 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: Problems with speed & issues with coercion in OS 9.2.2 (AppleScript 1.7)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problems with speed & issues with coercion in OS 9.2.2 (AppleScript 1.7)


  • Subject: Re: Problems with speed & issues with coercion in OS 9.2.2 (AppleScript 1.7)
  • From: Arthur J Knapp <email@hidden>
  • Date: Sat, 26 Jan 2002 18:10:52 -0500

> From: email@hidden
> Date: Sat, 26 Jan 2002 17:06:08 EST
> Subject: Problems with speed & issues with coercion in OS 9.2.2
> (AppleScript 1.7)

> ... I upgraded to OS 9.2.2 (from 9.2.1)
> and found myself with AppleScript having been upgraded to 1.7.

> renaming files within folders); I found that a lot of coercion issues came
> into play between whether file references are passed as strings or aliases
> (where before they were effectively interchangeable).

I believe that Jon's commands makes a number of string to file-spec
coercions, did you lose this particular scripting addition when you
upgraded?


> -- HANDLER b IsFolder
> -- Purpose: Determines if the current file is a folder (returns boolean)
> -- Expected Input: String or alias of path&filename
> -- Returns Output: Boolean, TRUE or FALSE

I like the above: it's clear and descriptive. :)


> local ValueForReturn -- boolean, Is path pointing at a folder?
> local TheRecordContents -- record, the complete contents of the file record

I'm afraid I don't understand the purpose of these. It is never nessesary
to declare a variable "local" at the top level of the script.

I think that what you wanted was to declare ValueForReturn and
TheRecordContents as "local" to IsFolder():

on IsFolder( param )

local ValueForReturn
local TheRecordContents


> on IsFolder(FullItemPathAndName)
>
> set TheRecordContents to (get info for (FullItemPathAndName)) as list
> -- item 7 in the list will be TRUE if it is a folder, FALSE if it is not
> (boolean)

Why are you coercing the "get info" record to a list? That is at least
one of the speed issues you are having. You want to avoid coercions that
are not nessesary.

> set ValueForReturn to (item 7 of (TheRecordContents)) as boolean
> return ValueForReturn as boolean


> When I write it as a stand-alone script (rather than a handler), it takes in
> the neighborhood of 12 seconds (on a G4/dual 800!) to get the info for
> (FullItemPathAndName); as a handler, it freezes the computer, hard.


OK, let's try this:

on IsFolder( string_or_alias )

-- This should assist with your coercion problems:
--
set alias_file to string_or_alias as alias

set infoRecord to info for alias_file

set returnValue to folder of infoRecord --> true or false

return returnValue

end IsFolder


Or even better:

on IsFolder( string_or_alias )

return folder of ( info for ( string_or_alias as alias ) )

end IsFolder


I should point out, however, that even the above will have the
potential to be very slow, if called repeatedly, (this has to do
with the fact that "info for" is a scripting addition command).
The following should be much faster:

on IsFolder( string_or_alias )

-- We say "as alias" first to make sure that the item
-- exists, and to ensure that there is a colon at the
-- end of the path.
--
return ( ( string_or_alias as alias ) as string )'s item -1 = ":"

end IsFolder


If you should happen to be fortunate enough to know that the
parameter will always be an alias, (and therefore the folder has
to exist), or a string that always has a trailing colon, (ie:
it was previously coerced from an alias), then you can drop
the "as alias" coercion:

on IsFolder( string_or_alias )

return ( string_or_alias as string )'s item -1 = ":"

end IsFolder



{ Arthur J. Knapp, of <http://www.STELLARViSIONs.com>
<mailto:email@hidden>
try
<http://www.acmetech.com/>
on error number -128
end try
}


  • Prev by Date: Re: Newbie. How do I count "i"?
  • Next by Date: Re: Can any tell me about error -1701?
  • Previous by thread: Problems with speed & issues with coercion in OS 9.2.2 (AppleScript 1.7)
  • Next by thread: Problems with speed & issues with coercion in OS 9.2.2 (AppleScript 1.7)
  • Index(es):
    • Date
    • Thread