Smart group/extension attribute for fonts?

AntonyaJ
New Contributor III

My company is starting to roll out our company fonts. Some computers already have them installed, and some don't. If I just push the fonts through a policy it installs in /Library/Fonts/Managed, but if they were installed by the user previously they'll be in /Users/<user>/Library/Fonts. The ones installed through the policy also modify the file names, which may or may not be the cause of the issue I'm trying to alleviate: duplicate fonts.

I'm installing a total of 84 fonts, all belonging to the same font family (or 2 font families, because mono spaced fonts are its own section in the font book). I attempted to create an extension attribute that will look for fonts installed by the user, and if the name is found and file count is at >84 it'll output true, else false. With this, I planned to create a smart group with which I can assign the new policy. However, the script on the extension attribute doesn't appear to be working properly (the count is outputting 1, not 85 like I get in terminal)(also, I'm super new to shell scripting), so I'm wondering: is creating an extension attribute and/or smart group the best way to make sure I'm not duplicating user installed fonts?

I also want to know what's wrong with what I've written, so insight into both the over arching question, and the script would be helpful!

 

#!/bin/sh

#Get current signed in user
 currentUser=$(ls -l /dev/console | awk '/ / { print $3 }')

#Get User Font Library
 fontLibrary=$(ls -l /Users/$currentUser/Library/Fonts | awk '/ / { print $9 }')
 
#count fonts present (extra line accounted for in if statement)
#there are a total of 84 fonts in the GT America library
 count=$(echo $fontLibrary | wc -l | awk '{ $1=$1;print }')
 
#GT Found
 found=$([[ $fontLibrary =~ .*GT-America.* ]] && echo "True" || echo "False")

#results
 if [[ $count > 84 && $found == "True" ]]                  
  then
    echo "<result>True</result>"
  else
    echo "<result>False</result>"
 fi

 

2 ACCEPTED SOLUTIONS

TheAngryYeti
Contributor
Contributor

I ran your script and it gave me "false" as the script output....to be used as an EA you need --> 

then echo "<result>True</result>"
else echo "<result>False</result>"

I would then spot check that the script is properly identifying what you want....you may want to not have it count all 84?(does that really matter?) from there you should be able to tailor a quick command to nuke the user installed directory of that font.

View solution in original post

AntonyaJ
New Contributor III

I guess it's been a while since I created a smart group because I forgot about the Advanced section. There are already attributes for fonts to filter with.

View solution in original post

4 REPLIES 4

TheAngryYeti
Contributor
Contributor

I ran your script and it gave me "false" as the script output....to be used as an EA you need --> 

then echo "<result>True</result>"
else echo "<result>False</result>"

I would then spot check that the script is properly identifying what you want....you may want to not have it count all 84?(does that really matter?) from there you should be able to tailor a quick command to nuke the user installed directory of that font.

Thanks! I realized I hadn't put the result tag and updated the script. I'm getting the result now, but the problem now is it's outputting 1 as the count instead of 84 (well, 85...). The count is important because not all of the font family may be installed. If I duplicate because only 30 are installed, that's okay with me. 114 fonts beats 168, imo.


@TheAngryYeti wrote:

from there you should be able to tailor a quick command to nuke the user installed directory of that font.


I also need to avoid nuking the directory, since other user-installed fonts may be present. But I could look into removing any fonts that start with the font family name.... I'll have to look into that. Thanks for the idea!

AntonyaJ
New Contributor III

I guess it's been a while since I created a smart group because I forgot about the Advanced section. There are already attributes for fonts to filter with.