Display dialog issue....


tell application "Finder"
	try
		set file_name to ((path to "dlib" from user domain as string) & ".webim.ini") as file specification
		display dialog "1"
	on error
		display dialog "2"
	end try
	set x to path to startup disk as text
	set y to x & file_name as alias
end tell


How do i get this to show Display dialog “1” when it found the file, and display dialog “2” when it hasn’t?

General:
¢ You do not need Finder for any of that. It is best to avoid application tell blocks that are not required.
¢ You can test for the existence of a file without Finder or System Events by trying to create an alias. Coercing to a file specification will not throw an error if the file does not exist. Alternatively, you can check for the existence of a file without a try block (tell application “System Events” to set it_is_there to exists file HFSpath).
¢ Paths from path to . already incorporate the path to the startup disk. Prepending it again will not work.

Portability:
¢ Unless your script is only run on Leopard or later, using path to . as Unicode text should be preferred over path to . as text (file/folder/volume names can have Unicode characters that can not be properly represented in pre-Leopard text or string classes).

If you control the placement of the file:
¢ The user’s Library folder seems like the wrong place so store an individual file. Either the Preferences folder or (a subfolder of the) Application Support folder would likely be better.

This works for me on Tiger:

try
	set file_alias to alias ((path to "dlib" from user domain as Unicode text) & ".webim.ini")
	display dialog "1"
on error
	display dialog "2"
end try

Model: iBook G4 933
AppleScript: 1.10.7
Browser: Safari Version 4 Public Beta (4528.16)
Operating System: Mac OS X (10.4)

Thanks! I’ll keep those hints in mind for sure! :slight_smile: