odd behavior from a file check script

I have a routine that checks for the existence of a folder that will be needed by the ASS app. It takes it’s info from a saved default.

It look like this:


--->elsewhere the value of defaultPath is set as something like:  "/Users/myuser/Desktop/theFolder/"

try
set searchPath to POSIX file defaultPath as Unicode text
tell application "Finder"
If exists folder searchPath then
--folder found code to proceed here
else
--folder not found, try default location
end if
end tell
end try
set searchPath to {{path to documents folder as string} & "theFolder:"} as string
try
tell application "Finder"
if exists folder searchPath then
set defaultPath to {{path to documents folder as string} & "theFolder:"} as string
else
--open a panel and have the user find it
end if
end tell
end try

if the folder is there on the first look, everything works. If it makes it to the second look (this is looking in the default location) it will find it if it is there. The problem comes when I try to extract the files from it after the path update. It would appear that one is a POSIX path and the other I have to convert to POSIX. before using.

I know how to convert to a POSIX path, how do I convert to a mac path?
or is there a way to get the full path to the user’s documents folder as a mac path?

Dee
Dee

Hi Dee,

I’d like to recommend to comment out all try blocks for debugging, which don’t have error handlers, to get some error message(s)

(path to documents folder as Unicode text) results the colon separated string path (of default class Unicode text)
you can specify a folder with:

set searchPath to ((path to documents folder as Unicode text) & "theFolder:")

Note: the braces work, but are wrong, you should use normal parentheses.
Braces in AppleScript are used only for lists and records

With the try blocks removed there are no errors reported. The problem is that if the path I am looking for is “Users/myuser/Documents/myFolder/” and it exists it will be found after I convert to POSIX path. When I use the ((path to documents folder) & “theFolder:”) checking for existence will always fail. If I substitute my own path “Macintosh HD/Users/myuser/Documents/theFolder/” it will find it.

the problem appears to be that it doesn’t like the colon separated path. Since I have no way of knowing the volume or username of the people using this application I have to use this to get the path.

The first time this is run the user has to specify the path via a open panel. This always return a slash separated path. I just want to do some error checking for this folder in subsequent runs.

dee

hm,

checking with the Finder, whether a folder exists, works only with colon separated paths
for example:

set defaultPath to POSIX path of ((path to desktop as Unicode text) & "theFolder:") --> /Users/myUser/Desktop/theFolder/

tell application "Finder"
	if exists folder defaultPath then
		say "yes"
	else
		say "no"
	end if
end tell

says always “no”

set defaultPath to POSIX path of ((path to desktop as Unicode text) & "theFolder:") --> /Users/myUser/Desktop/theFolder/

set searchPath to POSIX file defaultPath as Unicode text --> Mac HD:Users:myUser:Desktop:theFolder:
tell application "Finder"
	if exists folder searchPath then
		say "yes"
	else
		say "no"
	end if
end tell

answers the question “Does the folder theFolder exist on desktop” correctly

There is an alternative without the Finder to test either POSIX or HFS paths

set defaultPath to POSIX path of ((path to desktop as Unicode text) & "theFolder:") --> /Users/myUser/Desktop/theFolder/
try
	POSIX file defaultPath as alias
	say "yes"
on error
	say "no"
end try

or

set defaultPath to ((path to desktop as Unicode text) & "theFolder:") --> /Users/myUser/Desktop/theFolder/
try
	defaultPath as alias
	say "yes"
on error
	say "no"
end try

Thanks, seems that I can make this work although it seems that using a try/error as a branch instruction is not very clear coding practice.

dee