Any script to remove pages and Numbers casper policy?

parasarann
New Contributor II

Hi ,
We would like to remove the mac apps pages and numbers from MAC x for 'n' numbers of users, can I have any removal script to run via policy ?

1 ACCEPTED SOLUTION

stevewood
Honored Contributor II
Honored Contributor II

@parasarann the one downside to using a brute force method like that is on machines that do not have iWork '09 installed you will get errors in your script that could translate to a failure in the JSS. There are two ways (I'm sure many more) that you can get around this. You can either use an if .... then loop in the script to first test for the existence of the iWork '09 folder before attempting to delete, or you could use the method @talkingmoose showed, but apply to the Applications folder. I like this second method better because it's a little cleaner in the script and will get any version of Pages & Numbers. This would look like this:

#!/bin/sh

# Remove Numbers app
find /Applications -name Numbers.app -type d -exec rm -r {} +

# Remove Pages app
find /Applications -name Pages.app -type d -exec rm -r {} +

exit 0

That will use Find to locate those two apps anywhere in the /Applications tree of folders, and remove those apps.

View solution in original post

5 REPLIES 5

cddwyer
Contributor

To remove Pages or Numbers through a script you would just need to run:

#!/bin/bash

#Removes numbers app
rm -rf /Applications/Numbers.app

#Removes Pages app
rm -rf /Applications/Pages.app

In terms of removing it for n numbers of users, it is installed in the Applications folder which is available for all users of the machine so you can't really do this by user, also when you say from Mac 'x' this would be how you scope the policy.

Can you explain further what you mean by for Mac x for n users?

parasarann
New Contributor II

Hi , Thanks for posting the script. Actually in our machines we are having Iwork '09 & above versions mixed in both. We would like to remove only Pages, Numbers.app from machine.( Application must to removed for all local users from that machine)

we have filtered the computers which having Numbers,pages.app , its includes Iwork '09 and above

Above commands will remove the applications from I work 2013 and above only.So am looking for the script to search Iwork 09 from user machines and if its there it should remove iwork 09 apps, else it should remove the latest version from /Applications/Pages.app path

talkingmoose
Moderator
Moderator

This script will recurse through user home folders and list found items. You may want to use this before you actually run the script to delete them:

#!/bin/bash

# Remove Numbers app
find /Users -name Numbers.app -print

# Remove Pages app
find /Users -name Pages.app -print

find /Users = where to start the search
-name Numbers.app = what to find
-print = display the path to anything found

To actually delete items, you'll need the following (test first and use with caution):

#!/bin/bash

# Remove Numbers app
find /Users -name Numbers.app -type d -exec rm -r {} +

# Remove Pages app
find /Users -name Pages.app -type d -exec rm -r {} +

-type d = find directories (apps are nothing more than a top-level folder with sub- folders and files.
-exec = execute the following command...
rm -r = remove command with recursive argument to delete sub folders and files
{} = this is a placeholder for the list of found items
+ = remove every found item at once

parasarann
New Contributor II

Hi talkingmoose,

Thanks for sharing new way, i tried execute above one unfortunately it does not go well. So i have minimized my requirement and used below commands to remove Iwork 09 and latest versions from machine. Thanks

! /bin/bash

Remove Numbers app

rm -rf /Applications/iWork '09/Numbers.app
rm -rf /Applications/Numbers.app
Rm -rf /Users/*/Library/Preferences/com.apple.iwork.Numbers.plist

Remove Pages app

rm -rf /Applications/iWork '09/Pages.app
rm -rf /Applications/Pages.app
Rm -rf /Users/*/Library/Preferences/com.apple.iwork.Pages.plist

stevewood
Honored Contributor II
Honored Contributor II

@parasarann the one downside to using a brute force method like that is on machines that do not have iWork '09 installed you will get errors in your script that could translate to a failure in the JSS. There are two ways (I'm sure many more) that you can get around this. You can either use an if .... then loop in the script to first test for the existence of the iWork '09 folder before attempting to delete, or you could use the method @talkingmoose showed, but apply to the Applications folder. I like this second method better because it's a little cleaner in the script and will get any version of Pages & Numbers. This would look like this:

#!/bin/sh

# Remove Numbers app
find /Applications -name Numbers.app -type d -exec rm -r {} +

# Remove Pages app
find /Applications -name Pages.app -type d -exec rm -r {} +

exit 0

That will use Find to locate those two apps anywhere in the /Applications tree of folders, and remove those apps.