Posted on 03-15-2021 01:14 PM
Hey all. I finally got a chance to refine this little Self Service app and it works great. User can now pick a folder to sanitize in preparation for moving to the OneDrive Synch folder. Still have a lot of non-compliant Mac users who need to get important stuff in the Cloud. The script we have now in production doesn't give the user a choice. It automatically runs on their existing OneDrive Folder, which is okay, but I would like users to be able to run it in advance before they even sign into OneDrive for the first time to avoid synch errors right off the bat. Before this gets into production, however I have two questions.
Here's the script as it stands. It runs perfectly as a Self Service Item in our test instance of the latest version of JAMF pro.
#!/bin/bash
##crowdsourced by teodle and jamfnation
USER="$(stat -f%Su /dev/console)"
#logged in user chooses a folder
FOLDER=$(sudo -u $USER -H /usr/bin/osascript << EOD
tell application "System Events"
activate
set FolderName to POSIX path of (choose folder with prompt "Please choose a folder to sanitize")
end tell
EOD)
echo "$FOLDER"
cd "$FOLDER"
#now that a folder has been chosen, we run zmv command AS THE USER to remove, by brute force, all spaces, slashes and other illegals and replace them with underscore
sudo -u $USER -H /bin/zsh -c "autoload zmv && zmv '(**/)(*)' '$1${2//[^A-Za-z0-9.]/_}'"
sudo -u $USER -H /bin/zsh -c "autoload zmv && zmv '(/) ()' '$1$2'"
osascript -e 'display notification "Your Folder has been sanitized" with title "JAMF Management Notification"'
exit 0
Posted on 06-10-2021 05:52 PM
Hi Teodle,
How did you go with this? I am also looking for a solution. Thanks
Posted on 03-27-2023 08:55 AM
I like your script and would like to use it to prep for my organization's move to OneDrive folder backup. Seems we also need a function to shorten filenames that exceeds the OneDrive allowance. I have no idea how to code this.