Font Removal Script

New Contributor III

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.

#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.

#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.

Valued Contributor II
rm -v /Users/*/Library/Fonts/Gotham*

Bad :(

userList=$(ls /Users)
#actually should be something like (dscl . -list /Users NFSHomeDirectory|grep -v ^_) but I'm not going to code that out right now
for oneuser in $userList; do
      rm -v /Users/$oneuser/Library/Fonts/Gotham*

Better :)

Legendary Contributor II

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 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 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.

New Contributor III

Thanks all for the help. I appreciate the suggestions. My problem has not been with the script doing what it is supposed to do. The problem is running it at login. Any Ideas around that?

Valued Contributor II

Can you just have a policy and choose 'login' as the trigger?