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.
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.
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)