AppleScript tests for installed app without asking "Where is it"?

I’m trying to write an AppleScript application that will work in one way if Microsoft Word is installed, but another way if it isn’t installed.

If Word is not installed, is there any way to avoid the “Where is Microsoft Word” message, but still include the code that tells application Microsoft Word to various tasks if it is installed?

Many thanks for any help with this.

I guess that the final script isn’t supposed to be edited by its user.
In such case what you need is a code which compile on your machine with Word installed but drop the code dedicated to Word if it’s executed - as an application - on an other machine.

If I’m right, you may try this scheme :

try
	tell application id "com.microsoft.Word" to activate
	display dialog "Word is installed"
on error
	display dialog "Word isn't available"
end try

Yvan KOENIG running El Capitan 10.11.6 in French (VALLAURIS, France) vendredi 12 aout 2016 19:04:53

Thank you for this. That method certainly works for detecting Word, and this lets me avoid activating Word:

try
	tell application "Finder"
		set wordID to get application file id "com.microsoft.Word"
		set wordApp to wordID as alias -- I use this alias for opening files elsewhere in the code
		set wordInstalled to 1
	end tell
on error
	set wordInstalled to 0
end try

What I need to figure out - and I’ll be grateful for any help is how to “drop the code dedicated to Word” as you say in your post.

Perhaps I should put it in a Script Library inside the application bundle and call it if Word is present? Is there a more straightforward way?

Or the Cocoa (AppleScriptObjC) way

use framework "Foundation"

set wordInstalled to (current application's NSWorkspace's sharedWorkspace()'s absolutePathForAppBundleWithIdentifier:"com.microsoft.Word") is not missing value

An application is a bundle so you may have several scripts in it.
Foe instance you may have

myBundle.app/Contents/Resources/Scripts/useWord.scpt
myBundle.app/Contents/Resources/Scripts/dontUseWord.scpt

Then the main script would be :

try
	tell application id "com.microsoft.Word" to activate
	run script (((path to me as text) & "Contents:Resources:Scripts:useWord.scpt") as «class furl»)
on error
	run script (((path to me as text) & "Contents:Resources:Scripts:dontUseWord.scpt") as «class furl»)
end try

Yvan KOENIG running El Capitan 10.11.6 in French (VALLAURIS, France) vendredi 12 aout 2016 20:21:06

That is exactly what I needed to know. Thank you!