Posted on 12-05-2016 07:23 AM
Hello fellow jamfers,
I'm struggling with something here, I'm trying to write what I thought would be a simple script to remove a folder of templates, before I replace with new ones.
I'm finding that the RM command is not finding the files on all machines, mixed El Cap and Sierra, and that I have to specify .localized which makes me wary of the command running on the few machines I have over seas that run in French.
Any thoughts here?
This command,
rm -rf ~/Library/Group Containers/UBF8T346G9.Office/User Content.localized/Templates.localized/Insigniam
Seems required, and deleted the file on my computer
rm -rf ~/Library/Group Containers/UBF8T346G9.Office/User Content/Templates/Insigniam
This command, does not remove the folder, even though .localized does not show up in the Finder
Now when I run the command that works on my computer to my users, it doesn't seem to delete the folder on all my target machines, and because I'm using -rf, I suspect at least, I don't get any feedback, I did this purposely so that if the policy ran and this was a new user, I wouldn't get a false positive, as this script runs right before a new install of Microsoft Office templates which we roll out from time to time....
Hmmm, frustrating, anyone who can add light to this so I can create something more robust and reliable?
Posted on 12-05-2016 07:59 AM
Are you replacing ~/ with the logged in users home directory path?
Posted on 12-05-2016 08:36 AM
Ah right, scripts run as root, son of gun, I always struggle with an easy way to target the logged in user.
Posted on 12-05-2016 08:46 AM
What do you think of this?
user=`ls -l /dev/console | cut -d " " -f 4`
# office 365 template locations
rm -rf /Library/Application Support/Microsoft/Office365/User Content/Templates/Insigniam
rm -rf /Users/$user/Library/Group Containers/UBF8T346G9.Office/User Content.localized/Templates.localized/Insigniam
rm -rf /Users/$user/Library/Group Containers/UBF8T346G9.Office/User Content/Templates/Insigniam
Posted on 12-05-2016 08:49 AM
Depending on your need you could:
- Create a LaunchAgent that will run for each user that logs in
- Run the script once and loop through each existing user
- Run the script once for the current user only
From your example it sounds like you just want to run it for the logged in user, so you could do this:
loggedInUser=`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");'`
rm -rf "/Users/$loggedInUser/Library/Group Containers/UBF8T346G9.Office/User Content.localized/Templates.localized/Insigniam"
Posted on 12-05-2016 08:52 AM
I hear there are lot of ways to define $loggedInUser
Would the method I proposed work for Yosemite through Sierra?
Would your method work for Yosemite through Sierra?
Posted on 12-05-2016 09:13 AM
I switched to the python way a while back after reading MacMule's post here: https://macmule.com/2014/11/19/how-to-get-the-currently-logged-in-user-in-a-more-apple-approved-way/
I haven't had a problem with it on 10.9-10.11. I haven't tried either in 10.12 but wouldn't expect a difference. Most likely your way would work too, though the apple recommended python way isn't any harder to use so it seems like a good idea.
On my machine it doesn't look like /Users/$user/Library/Group Containers/UBF8T346G9.Office/User Content/Templates/Insigniam
exists, I think it's just the .localized folders (hidden extension).