Check if .plist file exists

I try to check if a .plist file exists in user library folder. Following this, I try:

property file_path : quoted form of POSIX path of ("~/Library/Preferences/org.MyFile.plist")

tell application "Finder" to set optsFound to exists file_path
		if optsFound then
			display dialog file_path
		else
			beep
		end if

Obviously file exist but I always get a beep :frowning:

And how can I set the path of the plist file without set the user’s name?
Thanks.

P.S. I try also this but din’t work.

One of the problems is “~/” will not get expanded in applescript

You could try this.

property library_folderPath : (path to preferences folder from user domain) as string
property file_ : "org.MyFile.plist"
property file_path : "" 
try
	set file_path to POSIX path of (library_folderPath & file_ as alias)
	
	display dialog file_path
on error
	beep
end try

You can lose some code by combining the first line and second,

property library_folderPath : (path to preferences folder from user domain) & "org.MyFile.plist" as string
property file_path : ""
try
	set file_path to POSIX path of (library_folderPath as alias)
	
	display dialog file_path
on error
	beep
end try

but I think it is better for editing and reuse to keep
the file name separate

Hi,

it’s strongly not recommended to assign a relative path to a property.
Once compiled the path is persisitent and the script is not protable.
You could check for an existing domain in the plist file with /usr/bin/defaults


property file_name : "org.MyFile"
property domain : "myDomain"

try
	do shell script "/usr/bin/defaults read " & file_name & " " & domain
	return true
on error
	return false
end try

Thanks a lot for both your reply.

@StefanK

Your statement is correct but I think that path to user’s preferences folder is quite absolute than relative, isn’t it?

I’m trying to ASOCifing scripts of portable applications, hoping it worth. I know are not a scripts masterpiece, just done with great passion for . Thanks for all your help.

No, path to preferences folder is a relative path (alias [startup disk]:Users:[current user]:Library:Preferences:)
At compile time the property will be set to the path to the preference folder of the current user.
It won’t work in a different user account unless the script will be recompiled

Thanks for the reminder of this Stefan.
Its probably best to try and remember this, even if it is being coerced into a POSIX path.