Re: Pathname Weirdness
Re: Pathname Weirdness
- Subject: Re: Pathname Weirdness
- From: Christopher Nebel <email@hidden>
- Date: Mon, 8 May 2006 10:44:03 -0700
On May 8, 2006, at 10:11 AM, Jonathan Piccolo wrote:
Full code for reference in case I'm doing something stupid (very
likely):
property antiPiracy : (path to preferences folder from user domain
as text) & ".aPCheck"
set folderName to ".aPCheck"
tell application "Finder"
if (not (exists alias folderName)) then
display dialog "This script was not installed correctly. Please
reinstall." buttons {"Quit"} default button 1
error number -128 --Quit was pressed
else
return 0
end if
end tell
You're getting closer, but there are still three errors, one obvious,
two not. First, the obvious one:
if (not (exists alias folderName)) then
"folderName" is merely the string ".aPCheck", so this isn't testing
for the existence of a folder named ".aPCheck" in the place that you
want, but rather in the Desktop folder. (The desktop is the implicit
container of otherwise unspecified Finder items.) What you want,
given the way the properties are now set up, is this:
if (not (exists alias antiPiracy)) then ...
Except that it isn't. This brings us to the first of the unobvious
errors. Finder will not admit to the existence of an invisible
folder if you refer to it as a "folder", but it will if you call it
an "item". This gives us:
if (not (exists item antiPiracy)) then ...
This works, but only on your machine! This is the second unobvious
problem: property values are evaluated at compile time and stored in
the script. This means that "antiPiracy" gets set to a path to
*your* preferences folder, which probably won't work on someone
else's machine. To get around this, simply don't use a property for
the path part:
if (not (exists item folderName of folder (path to preferences
folder))) then ...
Incidentally, System Events can also do this, but (a) has no scruples
about invisible items and (b) knows where the preferences folder is
itself, so you can simply say this:
tell application "System Events"
if not exists folder ".aPCheck" of preferences folder then ...
end tell
--Chris Nebel
AppleScript and Automator Engineering
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden