Declare Function dlopen Lib “System” ( path As CString, mode As Integer ) As ptr
Declare Function dlsym Lib “System” ( handle As PTr, name As CString ) As ptr
Const RTLD_LAZY = 1
Const RTLD_GLOBAL = 8
Dim libPtr As ptr = dlopen( “/System/Library/Frameworks/AppKit.framework/AppKit”, RTLD_LAZY Or RTLD_GLOBAL )
If libPtr = Nil Then return 0
Dim rvalue as Ptr = dlsym( libPtr, “NSAppKitVersionNumber” )
if rvalue <> nil then return rvalue.double
End Function
[/code]
Compare the double with the constant. So if you want to know if you’re running on 10.10, you would compare the return value with appKitVersionNumber10_10
Just like to add that this code was only possible thanks to Joe R, for teaching me how to access system constants.
// as of 10.4 apple provides 3 selectors so we can get the correct version number for things like 10.4.11
Dim sysMajorVersion,sysMinorVersion,sysBugVersion As Integer
call System.Gestalt("sys1", sysMajorVersion)
call System.Gestalt("sys2", sysMinorVersion)
call System.Gestalt("sys3", sysBugVersion)
Now you have all the correct OS X values[/quote]
I think we’ve discussed this before, Gestalt has been deprecated (still works, but for how long).
Starting with Yosemite, there is now a function on NSProcessInfo called “operatingSystemVersion” which returns a structure containing these values. Ironically, you need a method to detect if you’re running on 10.10 before you can figure out if you’re running on 10.10
I forgot to add, that the OSVersion function uses the correct method of getting all 3 places on Yosemite and then reverts back to Gestalt on 10.9 or lower.
[quote=134860:@Sam Rowlands]I think we’ve discussed this before, Gestalt has been deprecated (still works, but for how long).
[/quote]
True - deprecated as of 10.8 so its on life support and Apple seems to be more aggressive about removing things
Usually they have / had been waiting til there was a decent replacement in wide usage (NSProcessInfo) and then they’ll remove things
The AppKitVersion number is really a round about way
if (appKitVersionNumber <= appKitVersionNumber10_7)
/ / On a 10.7.x or earlier system
elseif (appKitVersionNumber <= appKitVersionNumber10_8)
// On a 10.8 - 10.8.x system
elseif (appKitVersionNumber <= appKitVersionNumber10_9)
// 10.9
elseif (appKitVersionNumber <= appKitVersionNumber10_10)
// 10.10
end if[/code]
[quote=134887:@Sam Rowlands]Won’t work if you intend to distribute via the App Store.
If there is an API for doing something, unless the API is broken, use the API.[/quote]
Hi Sam,
I have no intention of distributing Apps for AppleStore, my segment is aimed at companies that already got it today and using my solutions for process automation on graphical area, a very small segment installed directly on the machines for me .
[quote=134908:@jean-yves pochez]I get the system version by looking at the file
volume/System/Library/CoreServices/SystemInfo.plist
but dont know if it’s still possible from an accepted macapp store application ?[/quote]
As Apple have provided approved ways of getting the version number (which the code I provided above uses), I wouldn’t suggest doing it any other way. Apple have a habit of blocking off ways to do things that they don’t approve of.
This is true Sam, but you think Apple would block via Applescript in the near future ?
Starting Apple i share nothing but I find it hard to be a native technique and system that already works for years, what you think ?
[quote=134948:@Paulo Vargas]This is true Sam, but you think Apple would block via Applescript in the near future ?
Starting Apple i share nothing but I find it hard to be a native technique and system that already works for years, what you think ?[/quote]
The issue is mostly for the Apple Store. At the moment, there is no indication that non-MAS apps will not be able to use AppleScript.
[quote=134948:@Paulo Vargas]This is true Sam, but you think Apple would block via Applescript in the near future ?
Starting Apple i share nothing but I find it hard to be a native technique and system that already works for years, what you think ?[/quote]
If you’re asking for my opinion, it would be to use the API. This is how Objective-C & Swift apps get this information and that’s all Apple really cares about.
As for something that’s worked for years and suddenly gets broken, it does happen. See my thread on the removal of NSSharingService for 32-Bit applications.
Apple Script is a funny thing, it’s very useful, but it can’t really be used from a Sandboxed application (which of course is required for MAS).
Ultimately it’s up to you how you do it, APIs are the most reliable way and should be the most future proof, but if you want to use Apple Script, dig into system packages and extract information, it works now, for how long, only the engineers at Apple know.
[quote=135011:@Sam Rowlands]If you’re asking for my opinion, it would be to use the API. This is how Objective-C & Swift apps get this information and that’s all Apple really cares about.
As for something that’s worked for years and suddenly gets broken, it does happen. See my thread on the removal of NSSharingService for 32-Bit applications.
Apple Script is a funny thing, it’s very useful, but it can’t really be used from a Sandboxed application (which of course is required for MAS).
Ultimately it’s up to you how you do it, APIs are the most reliable way and should be the most future proof, but if you want to use Apple Script, dig into system packages and extract information, it works now, for how long, only the engineers at Apple know.[/quote]
Yes agree with You and Michel, but I think this time I will still use AppleScripts for if by chance AppleScripts are depreciated I do not really know how I’m gonna get because I have lots of functions for interacting with the Adobe software package that simply would not be accessible and hence capture the version of the OS is the least worry.
Yes my friend Michel, I even studied and still studying these possibilities but without AppleScripts them interact with the software to generate a plugin or something is a very complicated task, but it is up there as well in some limited functions and as my area is graphical I am without many options.