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

automatorfindermacosoffice-365

I am currently transitioning my files from local to a OneDrive folder on my mac and after I have copied all of the files in I have hundreds of Sync issues which relate to file names containing spaces at the front.

I am fairly new to coding / automator and looking around on the internet is fairly daunting!

Is there an easy way to just select the folder you want and then remove all leading whitespace inside of that folder? I have used automator before but dont understand any of the coding associated.

My OneDrive folder sits in Macintosh HD⁩ ▸ ⁨Users⁩ ▸ ⁨xxxxx directory so is there a way of setting the folder there and then running something to remove all leading spaces?

If possible, a laymans guide would help! haha

Any help would be much appreciated! Thanks!

Best Answer

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

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.

Related Question