You could make an extension attribute for the version number with a command like this:
defaults read /System/Library/CoreServices/Screen Sharing.app/Contents/Info.plist CFBundleShortVersionString
The command works when I run it in Terminal on a machine and returns the version number, but when I create an extension attribute using that command it always returns as blank.
Extension Attributes must echo back any result within <result></result> tags or you get a blank result.. In other words, like this-
echo "<result>$version</result>"
Jacob's command above was only an example of what to use, not a full Extension Attribute script.
#!/bin/sh
version= defaults read /System/Library/CoreServices/Screen Sharing.app/Contents/Info.plist CFBundleShortVersionString
echo "<result>$version</result>"
Close. Your script needs to store the variable as the output of the command. You can do so by putting in between a $ and two parentheses:
#!/bin/sh
version=$(defaults read /System/Library/CoreServices/Screen Sharing.app/Contents/Info.plist CFBundleShortVersionString)
echo "<result>$version</result>"
The entire defaults command must be enclosed either by back ticks or using the $(..) syntax. Meaning one of these-
version=`defaults read /System/Library/CoreServices/Screen Sharing.app/Contents/Info.plist CFBundleShortVersionString`
version=$(defaults read /System/Library/CoreServices/Screen Sharing.app/Contents/Info.plist CFBundleShortVersionString)
I personally always prefer the latter $(command) syntax, but either one will work, so its up to you. The way you have it now is not actually setting up the variable, which is why it returns as blank.
Just one more note. For something as simple as this, you actually don't even need to assign a variable. Since ScreenSharing.app should exist on almost any Mac unless its running an extremely old OS, something like this would also work-
#!/bin/sh
echo "<result>$(defaults read /System/Library/CoreServices/Screen Sharing.app/Contents/Info.plist CFBundleShortVersionString)</result>"
To be fair, you should probably mark Jacob's response as the answer, because he provided the defaults command to get the version string. All I did was clear up confusion on how to build an EA script.
Thank you, it wasn't working first but then I realized I had set the data type to "string" instead of "integer"
@mm2270 But yours provided better detail...
You both helped a lot, thanks!