Hey guys,
I am writing a script for use as an extension attribute which will check for the existence of Sublime Text.app, check that the console user isn't a local admin or root, and then go an check both Sublime Text 2 and also Sublime Text 3 and report back on whether either or is licensed. The script seems to be working for the most part, but I am getting a failure on the defaults read even though it should not be running when Sublime isn't installed (the script should just return "NA" to the JSS and exit). Any ideas?
#!/bin/sh
thisUser=`stat -f '%u %Su' /dev/console | awk '{ print $2 }'`
STV=`defaults read /Applications/Sublime Text.app/Contents/Info.plist CFBundleIdentifier`
if test -e /Applications/Sublime Text.app; then
if [ $thisUser = "root" ]; then
echo "User is root, bailing."
exit
elif [[ $thisUser == *admin* ]]; then
echo "User is the local admin, bailing."
exit
else
echo "User is not root or the local admin, checking Sublime Text."
if [ "$STV" == "com.sublimetext.2" ]; then
if test -e /Users/"$thisUser"/Library/Application Support/Sublime Text 2/Local/License.sublime_license; then
echo "<result>ST2 Licensed</result>"
else
echo "<result>ST2 Unlicensed</result>"
fi
fi
if [ "$STV" == "com.sublimetext.3" ]; then
if test -e /Users/"$thisUser"/Library/Application Support/Sublime Text 3/Local/License.sublime_license; then
echo "<result>ST3 Licensed</result>"
else
echo "<result>ST3 Unlicensed</result>"
fi
fi
fi
exit
else
echo "<result>NA</result>"
exit
fi
Heres what I get:
<result>NA</result>
2015-11-20 13:07:39.667 defaults[42900:4252084]
The domain/default pair of (/Applications/Sublime Text.app/Contents/Info.plist, CFBundleIdentifier) does not exist