Is there a way to bypass the "Choose Application" window?

I’ve got a script in the works that will be GUI scripting a couple different applications, and upon the script launching, I would rather have it check if said applications exist instead of popping up the "Choose Application " window. This would be nice because I could provide a list of required applications and where to download them when the script can’t find them. Thanks! :smiley:

Here’s a way to check if an application exists. You can put it in a try block and if it errors then the app doesn’t exist.

set theApp to "Safari"
set appPath to (path to application theApp as Unicode text)

Hi,

member Mikey-San has written a Foundation tool to do this, you can find it here

or this plain AppleScript solution, using the file id:

check_Application_exists("com.apple.finder")

on check_Application_exists(theApp)
	try
		tell application "Finder" to application file id theApp
		return true
	on error
		return false
	end try
end check_Application_exists

In case anyone else needs an example, here’s what I whipped up and I believe will preform quite nicely in my program. Note this is only a bit of it from the beginning of the script.

choose from list {"Full OGM to MP4", "Demux OGM", "Convert Audio Tracks", "Mux Audio and Video", "Convert AVI to MP4"} OK button name "Continue"
tell result
	if it is false then error number -128 -- cancel
	set choice to first item
end tell

if choice = "Full OGM to MP4" then
	check_ffmpegX_Exists("com.mac.homepage.major4.ffmpegX")
	check_Vision_Exists("com.objectifmac.dvision3")
	check_EasyWMV_Exists("easywmv")
	OGM_Parts()
	Track_Num()
	DemuxOGM()
else if choice = "Demux OGM" then
	check_Vision_Exists("com.objectifmac.dvision3")
	OGM_Parts()
	DemuxOGM()
else if choice = "Convert Audio Tracks" then
	check_ffmpegX_Exists("com.mac.homepage.major4.ffmpegX")
else if choice = "Mux Audio and Video" then
	check_Vision_Exists("com.objectifmac.dvision3")
else if choice = "Convert AVI to MP4" then
	check_EasyWMV_Exists("easywmv")
end if

on check_ffmpegX_Exists("com.mac.homepage.major4.ffmpegX")
	try
		tell application "Finder" to application file id "com.mac.homepage.major4.ffmpegX"
	on error
		display dialog "You do not have \"ffmpegX\" installed."
		open location "http://homepage.mac.com/major4/"
	end try
end check_ffmpegX_Exists

on check_Vision_Exists("com.objectifmac.dvision3")
	try
		tell application "Finder" to application file id "com.objectifmac.dvision3"
	on error
		display dialog "You do not have \"D-Vision 3\" installed."
		open location "http://www.objectifmac.com/"
	end try
end check_Vision_Exists

on check_EasyWMV_Exists("easywmv")
	try
		tell application "Finder" to application file id "easywmv"
	on error
		display dialog "You do not have \"EasyWMV\" installed."
		open location "http://www.easywma.com/wmv/"
	end try
end check_EasyWMV_Exists

It seems to be doing exactly what it’s supposed to, so I hope I’ve nailed this portion of the script and can set it in stone :wink:

EDIT: By the way, I wasn’t really sure what (tell application “Finder” to application file id “x”) does so I left it as it was. :confused:

Hi,

every application has an internal file id. The Finder throws an error, if the file id doesn’t exist.

btw: here is a optimized version of your script with only one handler. :slight_smile:
the parameter of the check_app_Exists() handler can be a single name or a list of names

property appList : {{"ffmpegX", "com.mac.homepage.major4.ffmpegX", "http://homepage.mac.com/major4/"}, ¬
	{"D-Vision 3", "com.objectifmac.dvision3", "http://www.objectifmac.com/"}, {"easywmv", "EasyWMV", "http://www.easywma.com/wmv/"}}

choose from list {"Full OGM to MP4", "Demux OGM", "Convert Audio Tracks", "Mux Audio and Video", "Convert AVI to MP4"} OK button name "Continue"
tell result
	if it is false then error number -128 -- cancel
	set choice to first item
end tell

if choice = "Full OGM to MP4" then
	check_app_Exists({"ffmpegX", "D-Vision 3", "EasyWMV"})
	OGM_Parts()
	Track_Num()
	DemuxOGM()
else if choice = "Demux OGM" then
	check_app_Exists("D-Vision 3")
	OGM_Parts()
	DemuxOGM()
else if choice = "Convert Audio Tracks" then
	check_app_Exists("ffmpegX")
else if choice = "Mux Audio and Video" then
	check_app_Exists("D-Vision 3")
else if choice = "Convert AVI to MP4" then
	check_app_Exists("EasyWMV3")
end if

on check_app_Exists(chkApps)
	repeat with i in chkApps as list
		repeat with j in appList
			if item 1 of j is contents of i then
				try
					tell application "Finder" to application file id (item 2 of j)
				on error
					display dialog "You do not have " & quote & (item 1 of j) & quote & " installed."
					open location item 3 of j
				end try
			end if
		end repeat
	end repeat
end check_app_Exists

.< Boy that optimization is a rush for me! I’m having difficulty interpreting it… I’ll just have to read through it a few times slowly and understand what exactly it’s doing. I knew you could optimize it the way you did by using one handler, but I had no idea how. :wink:

EDIT: Genius. Simply genius. :slight_smile: I wouldn’t have optimized it by myself for a long time and even then, it probably would have taken me awhile to come up with something so brilliant! :smiley: Your the best Stefan!