Cant Get a If Statement to Work :(

Hi Guys,

I cant get this to work, any ideas?


set AppInstall to (path to applications as text) & "MyProg:iDrive.app"

if exists file AppInstall then
	
	say "Hello"
	
else
	say "Doh"
	
end if

end

This is the error: “Can’t make every application into type constant.” number -1700 from every application to constant

Resolved it:


set msg to "no"
tell application "Finder"
	if exists POSIX file "/applications/My Progs/iDrive.app" then
		set msg to "yes"
	end if
end tell

display dialog msg

Hi,
guess there’s no need for the posix …


set AppInstall to (path to applications folder as text) & "Utilities:Terminal.app"

if exists application AppInstall then --you can remove"application" as it'll start running
	
	say "Hello"
	
else
	say "Doh"
	
end if

end

two problems:
¢ the correct “shortcut” to /Applications is path to applications folder
¢ only System Events or the Finder knows about the existence of a file reliably


set AppInstall to (path to applications folder as text) & "MyProg:iDrive.app"
tell application "Finder" to set iDriveExists to (exists file AppInstall)
if iDriveExists then
	say "Hello"
else
	say "Doh"
end if

@Hans-Gerd: your script will throw an error, if the file doesn’t exist

Easy as this:

set AppInstall to ((path to applications folder as string) & "MyProg:iDrive.app")
tell application "Finder"
	if exists AppInstall then
		say "Hello"
	else
		say "Daoh"
	end if
end tell

Finder is the only application that will handle checking files from string.

P.S. I changed “Doh” to “Daoh” for pronunciation.

EDIT:
I just noticed Stefan said the same thing I did. :stuck_out_tongue:

@Stefan You’re right!
thx