How to remove leading whitespace in a folder for OneDrive upload on mac os

Here is a script that’s dedicated to fix this issue for OneDrive on the Mac.

  • https://github.com/soundsnw/mac-sysadmin-resources/blob/master/scripts/fix-onedrive-filenames-apfs.sh

It is quite sophisticated and very well documented.

  1. If you don’t have JAMF - remove those from the end - they fill fail harmlessly I believe if you don’t have the JAMF framework installed.
  2. It checks for APFS and makes a full backup of the existing files.
  3. It notifies you what it’s doing.
  4. It fixes folders first, then files.
  5. It trims white space from the front and end of files and folders and also corrects illegal characters like /
  6. It tries to catch errors, clean up, prevent sleep, avoid spotlight going ballistic while the files are being renamed, etc..
  7. There’s nothing about this script I don’t like, to be honest.

It has no warranty, but please ask if you think you need help modifying it. I did not write it, but the community of mac administrators that makes and shares these are some of the best resources I know for great tools.