Launch specific version of application

This part of code I’m having issue is a launch code at the very end of an installer of a connection file.

The Program’s Version 5 is a torrent only program. Version 4 runs on a particular kind of open p2p network & this code is intended for those that use version 4.

Objective. Find a version of ZZZZ that has a bundle version less than 5 & to launch it. If only a ZZZZ version is found that is 5 or greater then show dialog only version 5 installed. Else display dialog ZZZZ not found.

Whilst with the newer OSX’s it’s less likely someone will have two versions installed, it’s still possible.

Considerations: Application might not be located in Apps folder. App might have had its name partially changed (such as if both ZZZZ version 4 & 5 exist in Apps folder.)

There’s two ways to identify ZZZZ. (1) One is via the app id, example: “ZYUX”
Version 4 used capitals for ZZZZ, version 5 doesn’t (zzzz).
(2) There’s also the url such as “com.slkjls.wuw” which is only used by version 4.

Whilst version 5 can no longer be identified by that same url, there are clone programs that use the identical url. Yeah this makes it more complicated. I had tried to combine both ID’s but doubt I did it correctly. :frowning:
Example:

tell application "Finder" to set appName to open (application file id "com.slkjls.wuw" and "ZZZZ" as string)

The version code I used below was borrowed from this forum. :smiley:



if response is (localized string of "Launch ZZZZ") then
	tell application "System Events"
		try
			set ZYUt_list to paragraphs of (do shell script "find /Applications -name ZZZZ.app")
			repeat with ff_installed in ZYUt_list
				-- get version
				set ff_ins_info to property list file (ff_installed & "/Contents/Info.plist")
				set ff_ins_version to (value of property list item "CFBundleVersion" of ff_ins_info)
				if ff_ins_version is less than 5 then
					tell application "Finder" to set appName to open (application file id "ZYUX" as string) -- launch version 4
					delay 3
					tell application "System Events" to set frontmost of process "ZZZZ" to true
					
				else
					display dialog "Found ZZZZ 5 on system, refuse to open it!" -- only version 5 found
					
				end if
			end repeat
		on error
			tell application "Finder" to set appName to open (application file id "ZYUX" as string)
			delay 2
			tell application "System Events" to set frontmost of process "ZZZZ" to true
		end try
	end tell

A few issues I can see are: (1) The search horizon is limited to the Application folder. (2) If the program’s name has been changed, then this effects the outcome. (3) AFAIK Unix is incapable of a wildcard search (example: ZZZZ*.app or ZZ*.app)

If I change the name of ZZZ.app version 5 to ZZZ5.app & leave version 4 at ZZZ.app within the Applications folder then version 4 launches. Or if vice versa then the version 5 dialog appears.

“tell application “System Events” to set frontmost of process .” if the person has even partially renamed the app then this process does not work & errors. Unless another method such as begins with ZZZ is used, however that could be done. Or if the app ID is used perhaps. I incorporated this because I found ZZZZ was seemingly not launching in front & just seemed to have its icon in the Dock on Mavericks (but otherwise launches fine in Snow.)

I just realised my error code should probably just give a dialog & say “No version found to launch”.

The addition of the version checking means the launch process takes several seconds longer.

Any way to improve & better define the script to reach the objective?

Model: MacPro
Browser: Firefox 25.0
Operating System: Mac OS X (10.6)

I’ve experimented with this for a while. No happy medium. I know the concept is an unusual one, but this does occur when an app (open source) is no longer developed for a particular purpose. I simply try to do the fixes that relate to the purpose the app was originally designed for.

I’m guessing there’s an OSX issue nowadays with this topic. Otherwise I’m sure someone would have had a clue. I’m not very intelligent & only use AS when I feel needed which is my downfall. The script I was trying to write is not for myself but for others, as have all the other scripts I’ve posted about on this forum.

I’ll just leave it up to the user to make adjustments where needed which might seem annoying for them for a time. They’ll learn.

I’m personally sticking to SL since I dislike Mavericks for the most part & Yosemite is apparently not much different. I’m happy with my discontinued apps instead of trying to find & pay for 3rd class replacements to work on the newer OSX’s (research shows nothing comes near some of the older apps, thanks Apple.) I guess the new MacPro shows Apple’s attitude now; a computer that lacks the expansion always expected from an MP. And video cards that are duplicates renamed of other ‘older’ models with no improvements, specifically ordered by Apple. Specifications speak for themselves (forget the marketing hype, you are not getting anything special.) And only a single multi-core processor. ‘Cough’ … heck Apple is definitely going cheap on us aren’t they; not the super machines they once offered compared to their competitors.

Model: MacPro
Browser: Firefox 25.0
Operating System: Mac OS X (10.6)