Script to remove old versions of FileMaker Pro

jgwatson
Contributor

I hoping by the end of this thread someone will be able to tell me why this script isn't working. Hoping once it has been fixed, others will use as needed. Thank you - this just fails.

!/bin/sh

!/bin/bash

loggedInUser=/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'

rm -rf /Applications/FileMaker Pro 12/FileMaker Pro.app
rm -rf /Applications/FileMaker Pro 13/FileMaker Pro.app
rm -rf /Applications/FileMaker Pro 14/FileMaker Pro.app
rm -rf /Applications/FileMaker Pro 15/FileMaker Pro.app

exit 0

5 REPLIES 5

sdagley
Esteemed Contributor II

@jgwatson When pasting a script, use three consecutive backpack characters (```) before and after the script so the forum software displays it as code.

To answer your question, when working with files that have spaces in their names you either need to quote the name or escape the space:
rm -rf /Applications/FileMaker Pro 12/FileMaker Pro.app or rm -rf "/Applications/FileMaker Pro 12/FileMaker Pro.app"

A couple of other minor nits: There is no need for determining the logged in user in that script, and you only want one #!/bin/... in your script

mschroder
Valued Contributor

I don't know how FileMaker is being installed, but you might have other directories or the package receipts that you might want to remove. I have seen some un-install scripts that leave a lot of stuff on the Mac. It rarely does harm, but it can be confusing - in particular when you use the existence of a receipt as indicator for the existence of the software.

Is there a reason that you want to keep "/Applications/FileMaker Pro 12" and other files or directories that might be in there, and only remove "/Applications/FileMaker Pro 12/FileMaker Pro.app"? To me it seems more logical to remove the complete "/Applications/FileMaker Pro 12".

I always would check first whether a directory exists before boldly running the command to remove it. So I would do

#!/bin/sh
for theDir in /Applications/FileMaker Pro 12 /Applications/FileMaker Pro 13 /Applications/FileMaker Pro 14 /Applications/FileMaker Pro 15; do
    if [ -d "$theDir" ]; then
        /bin/rm -rf "$theDir"
    fi
done

Hope this helps.

jgwatson
Contributor

Thanks @mschroder , apologies for being a pain, but how would I go about deleting the icon from the dock if it was there?

What would that line look like?

Thanks

mschroder
Valued Contributor

Hm, that is a very good question, unfortunately I don't know how to do that. But in fact it would be a good idea to check whether the icon is in the dock, and in that case remove it. I had never thought about that one...

sdagley
Esteemed Contributor II

@jgwatson dockutil is the tool you’d use to manipulate Dock items. You’ll find many references to it if you search Jamf Nation.