ASOC and Using Macintosh HD in file paths

Hi all,

This new ASOC is really baffling me sometimes. I’m trying to do something really simple and it just wont let me do it. I want to check if a file or folder exists

as an example here I’m trying to see if the desktop folder exists


	on clicked_(sender)
		
		try
			tell application "Finder"
				set imageFile to ":Users:keat:Desktop" as alias
				display alert "Found"
			end tell
		on error
			display alert "Not Found"
		end try
		
	end clicked_

But there is always an error and the Not Found alert is activated. The only way I can fix this is to make the file path “Macintosh HD:Users:keat:Desktop”. However I want this application to be as portable as possible so having Macintosh HD out the front really isnt good enough. This script works in AS editor but not Xcode. The strange thing is I have another app made with ASOC using the same kind of script to check if a file exists and it works fine!

Any ideas? Am I doing something ridiculously stupid?

Cheers

Model: MacBook
AppleScript: Xcode 3.2.1
Browser: Safari 531.21.10
Operating System: Mac OS X (10.6)

Hi,

regardless of ASOC or AppleScript a path specification like “:Users.” is wrong syntax.
HFS paths (colon separated) start always with a disk name, unlike POSIX paths which could start with a slash for the startup volume.

For portability it’s always recommended to use relative paths e.g. path to desktop returns the alias to the desktop folder of the current user


on clicked_(sender)
	try
		set imageFile to path to desktop
		display alert "Found"
	on error
		display alert "Not Found"
	end try
end clicked_

Cool thanks!

Howcome :Users sometimes works? Just for future reference.

And what folders can you assign relative paths to?

Thanks again

sometimes AppleScript is very polite and ignores user mistakes :wink:

Open the Standard Additions dictionary in Script Editor and look at path to