Re: Name of this folder
Re: Name of this folder
- Subject: Re: Name of this folder
- From: Richard 23 <email@hidden>
- Date: Mon, 12 Mar 2001 14:28:22 -0800
>
>> Explanation:
>
>>
>
>> ":" as alias
>
>>
>
>> retuns the path to the container of the script. Note this is a 'trick' you
>
>> won't find in the dictionary. In fact, I don't understand it myself. Just
>
>> something some clever dude figured out ;)
This has always seemed like a misfeature, at least partially.
If you write scripts manipulating path strings, a logical value for
a non-existing item would be the empty string. Trapping an exists
test would logically fail on an empty string but not in this case.
Now if it really gave the path to the SCRIPT FILE rather than the current
application I might be a little more appreciative. Path to me would be
more handy if it didn't return "path to my daddy" rather than path to me.
and jeepers, why bother with the colon. I've always used:
"" as alias
or something built on top of that:
-- ---------------------------------------------------------
-- Preprocessed by Convert Script 1.0d5
-- ---------------------------------------------------------
-- author: Richard 23, date: Monday, March 12, 2001
-- ---------------------------------------------------------
get Fss("foo")
--> file "Private:Apple Extras:AppleScript:foo"
get Fss({path to startup disk, "templog"})
--> file "Private:templog" on Fss(theFile)
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
on Fss(theFile)
file (theFile as string) as file specification
end Fss
-- ---------------------------------------------------------
The file doesn't have to actually exist of course neither must
it be a file...a folder path is fine. Although I don't think
you can make a file spec for a volume which is not present.
To test for exists try coercing to an alias, trapping the error
in case it doesn't exist, making sure also to be sure that it's
not the empty string...because the empty string coerces to the
current path's folder making it appear that "" exists!
-- ---------------------------------------------------------
-- Preprocessed by Convert Script 1.0d5
-- ---------------------------------------------------------
-- author: Richard 23, date: Monday, March 12, 2001
-- ---------------------------------------------------------
on exists theFile
try
theFile as alias
theFile's contents /= ""
on error
false
end try
return result
end exists
-- ---------------------------------------------------------
and if you want to extend exists to check that a script library has
been loaded (a one-time initialization step in some scripts), you
can do that as well... Here's a slightly smarter exists handler:
-- ---------------------------------------------------------
-- Preprocessed by Convert Script 1.0d5
-- ---------------------------------------------------------
-- author: Richard 23, date: Monday, March 12, 2001
-- ---------------------------------------------------------
on exists theObj
try
if theObj's class is in {application, handler, script} then
true
else if result is in {alias, file specification, string} then
theObj as alias
theObj's contents /= ""
else
continue exists theObj
end if
on error
false
end try
return result
end exists
-- ---------------------------------------------------------
R23