Quick question. I have a script that removes the Gotham font family from users computer. I know that it could be a little dangerous using the wildcard but it seems to work ok. Here is the problem that I am running up against. The script works great when called from check in, running under the sudo user. I am trying to make this deployed safely so we are first having a policy that asked the user for restart. Upon restart or logging in I am calling the script. When called from the JSS I can’t seem to get it to run under the right user (with login hooks which I really can’t get working or with a startup script). I tried outset and I think that works for the system lvl font removal but not the user. Any help would be greatly appreciated.
#!bin/sh #This script is designed to remove all Gotham fonts from the /Library/Font + in the user library font folder as well. COUNT=$(rm -v /Library/Fonts/Gotham* 2> /dev/null | wc -l) COUNT1=$(rm -v /Users/*/Library/Fonts/Gotham* 2> /dev/null | wc -l) #searches the two locations on the computer where the Gotham font would live. This is an assumption but should cover the bases pretty throughly. COUNTTOT=$((COUNT + COUNT1)) #adds the two file locations and sets them as a variable for use later in the echo statement. echo "Removed $COUNTTOT Gotham Fonts" #reads out the total number of fonts removed.
You could possibly do this a little more concisely with mdfind (Spotlight command line)
For example, if I wanted to find all versions of Arial on my Mac, I might do something like this
mdfind 'kMDItemKind == "TrueType font" && kMDItemFSName == Arial*'
This produces the following list on my Mac:
/Library/Fonts Disabled/Arial.ttf /Library/Fonts Disabled/Arial Italic.ttf /Library/Fonts Disabled/Arial Bold.ttf /Library/Fonts Disabled/Arial Bold Italic.ttf /Library/Fonts/Arial Unicode.ttf /Library/Fonts/Arial Narrow Bold.ttf /Library/Fonts/Arial Narrow Italic.ttf /Library/Fonts/Arial.ttf /Library/Fonts/Arial Rounded Bold.ttf /Library/Fonts/Arial Bold Italic.ttf /Library/Fonts/Arial Italic.ttf /Library/Fonts/Arial Narrow.ttf /Library/Fonts/Arial Black.ttf /Library/Fonts/Arial Bold.ttf /Library/Fonts/Arial Narrow Bold Italic.ttf /Library/Fonts/Microsoft/Arial.ttf /Library/Fonts/Microsoft/Arial Italic.ttf /Library/Fonts/Microsoft/Arial Bold.ttf /Library/Fonts/Microsoft/Arial Bold Italic.ttf
Obviously this only locates any TrueType versions of Arial, so if there were other formats perhaps, it wouldn't pull them up. In this case, I'm ok with specifying TrueType since I doubt there are other Arial font types floating around. I suppose you could drop the
kMDItemKind query, but then you'd run the risk of grabbing a file with the word "Arial" in it if it was Spotlight indexed.
You could pass that result to a loop
rm command to remove them all from the Mac as it processes the above list.
In the case of the Gotham fonts, are they also TrueType, or some other format? I'm not familiar with that font, so I don't know.
Note that you can also direct mdfind to look only in a directory path. For example:
mdfind -onlyin /Users/ 'kMDItemKind == "TrueType font" && kMDItemFSName == Arial*'
This produces nothing since I'm telling it to only look in the
/Users/ directory and subdirectories. Since I don't have any local user level Arial's installed, it doesn't produce anything.
Hope that helps a little.