The first problem is:
if exists "~/Library/Preferences/test.plist"
You're checking to see if a string object exists. Of course it does.
There's nothing here that tells AppleScript you're trying to check a
file. As far as AppleScript is concerned, this is just a string of characters.
So, given that, the string needs to be coerced to some kind of file reference, and that's where you're falling down - there are several different ways of defining paths in AppleScript and you need to know which one you're dealing with. In this case, any UNIX-style path needs to be identified as such, via the
POSIX file class:
if exists POSIX file "~/Library/Preferences/test.plist"…
Now AppleScript understands that the string of characters represents a POSIX path and it can react accordingly.
At the end of the day, though, this is completely the wrong approach. You should avoid hard-coding paths like this since it makes your script non-portable. For example, when running Mac OS X in other languages you might not have a 'Library' directory, nor a 'Preferences' directory - you'd likely have a local translation of those words.
To that end, AppleScript provides the
path to command which uses the built-in System routines for finding common directories. In this case you want to know if the 'test.plist' file exists in the user's home directory, so this is how you should check:
set prefsFolder to (path to preferences from user domain)
tell application "System Events"
if exists file "test.plist" of prefsFolder then
return yes
else
return no
end if
end tell
This code is sure to work on any version of Mac OS X, regardless of the internationalization settings and it doesn't worry about Mac-style paths, UNIX-style paths, POSIX files or any of that other cruft.