Skip to content

Instantly share code, notes, and snippets.

@drblue
Last active April 16, 2024 21:54
Show Gist options
  • Save drblue/6fdc431396760f2440ce to your computer and use it in GitHub Desktop.
Save drblue/6fdc431396760f2440ce to your computer and use it in GitHub Desktop.
Fix OneDrive for Mac CPU usage
#!/bin/bash
## Fix OneDrive for Mac CPU usage
##
## Seems this is still a problem 5 years later after I created this little gist.
## I have long since stopped using OneDrive (luckily), but according to
## comments below, I have added the new path for OfficeFileCache for macOS
## Mojave (10.14) and Catalina (10.15).
## Run this on macOS Mojave (10.14) and Catalina (10.15)
find ~/Library/Containers/ -type d -name OfficeFileCache -exec rm -r {} +
## Run this if you're on pre-Mojave (< 10.14)
find ~/Library/Group\ Containers/ -type d -name OfficeFileCache -exec rm -r {} +
@stephenhollifield
Copy link

I had the same issue with my MacBook Pro 2016 getting hot to the touch. I did some research and found that Apple modified the temperature at which they will turn the fans on due to complaints about loud fan noise. Unfortunately, this means they wait until the temperature is very high before it will increase fan speed. This high temperature kicks in the thermal CPU throttling mechanism slowing your Mac down. I found this app very helpful to show me the component temps and ability to manually control the fan speed: https://crystalidea.com/macs-fan-control
I've been using it successfully for over a month.

@gec118
Copy link

gec118 commented May 27, 2020

Group, my research found that the high cpu was directly a result of a process called "distnoted." The approach I follow now is when I experience high cpu, I open activity monitor (cpu tab), sort on cpu %, find the distnoted process demanding high cpu, double-click on it and then quit the process. After a few seconds, there is an immediate change in the fan speed and cpu consumption. There is an article defining distnoted here:
https://www.techradar.com/how-to/computing/apple/ask-what-is-distnoted-on-mac-1305721
Hope this helps you. It solved my problem.

BRILLIANT THANKS. I've always been quitting OneDrive and only opening it as needed, which is a pain in the ass. Being able to quit disnoted will be much better. I've already tried it and it seems to work in turning down my fan. (Still only a partial solution - why can't MS fix this?)

Actually, it didn't work for me. Nothing has. I'm actually not sure that it is ONLY OneDrive's fault, although it does go into overdrive and heat my Mac up. But my MacBook Pro 2019 just gets very hot very quickly - actually hot to the touch above the Touch Bar (not warm, definitely hot). 2 days ago, I tried doing a huge factory reset and reinstalling all the main programs from the Internet. Not even from a Time Machine backup. The problem came back very quickly.

In my never-ending saga, I have now solved the problem for several months by a complete reinstall of everything. I figured that since my documents are in the cloud anyway, I could simply take screenshots of Launchpad to show all the apps I have installed, do a total reinstall of the OS (https://support.apple.com/en-us/HT204904), and reinstall all the apps one-by-one. It took one evening. Once my OneDrive had completed a very long sync, the computer cooled down, the fan has been almost entirely off, and my Mac has been cool and silent ever since.

@bohemier
Copy link

This script does not seem to fix the problem of distnoted, onedrive and onedrive finder integration going wild on my 2 macs. Despite reinstalling macos and reinstalling onedrive, the problem is still there. Only way I got it to calm down is to use AppPolice (https://github.com/AppPolice/AppPolice) and restrict these processes to 20-30% max usage.

@aschain
Copy link

aschain commented May 30, 2020

Just had this problem on OS X Catalina, and based on the above (deleting a cache), the below seemed to work for me:
Quit OneDrive, run:
rm -r ~/Library/Caches/com.microsoft.OneDrive
then relaunch.

Or if you want to be safer, instead run:
mv ~/Library/Caches/com.microsoft.OneDrive com.microsoft.OneDrive.backup

@rogercrocha
Copy link

This seems to work for me on my Mac Majove: https://www.hightechdad.com/2017/02/06/onedrive-sync-issues-how-to-reset-onedrive-for-mac-the-easy-way/

this link is broken

This is the link for the official Microsoft KB article. It worked for me.

https://support.microsoft.com/en-us/office/reset-onedrive-34701e00-bf7b-42db-b960-84905399050c

@hallard
Copy link

hallard commented Jul 2, 2020

I use also an easy dirty way just in case, from one drive app just select pause sync for 2H (or more), not the best one but works

just tested rm -r ~/Library/Caches/com.microsoft.OneDrive we'll see (for now looks to work) but removing office file cache never solved my issue (on 2 mac mini)

@jonathanmccormack
Copy link

I ran into an error:

$ find ~/Library/Containers/ -type d -name OfficeFileCache -exec rm -r {} +
find: fts_read: Invalid argument

Adding single quotes around the {} fixed that for me, in case anyone else runs into the same issue:

find ~/Library/Containers/ -type d -name OfficeFileCache -exec rm -r '{}' +

@logangarcia
Copy link

This worked for me, thanks so much!

@TheDaveKurth
Copy link

It could be user error but I still get "Operation not permitted" and I just got a brand new mac with Catalina. Any pointers would be highly appreciated.

@jeremyfuksa
Copy link

It could be user error but I still get "Operation not permitted" and I just got a brand new mac with Catalina. Any pointers would be highly appreciated.

I got that, too. But the script did seem to do the trick regardless.

@TheDaveKurth
Copy link

Thank you for your feedback. It didn't work for me unfortunately. So I deleted OneDrive all together and not sure yet what I'll do instead. I already got used to the fact that my files are synced across all devices.

@gec118
Copy link

gec118 commented Oct 23, 2020

Thank you for your feedback. It didn't work for me unfortunately. So I deleted OneDrive all together and not sure yet what I'll do instead. I already got used to the fact that my files are synced across all devices.

See my solution from 27 May. It's drastic but my Mac has been perfectly fine ever since. No more overheating. One evening of reinstalling is all that it cost me. It might be worth a shot.

@horstt
Copy link

horstt commented Dec 21, 2020

Concerning the 'Operation not permitted' errors: these have to do with Terminal permissions. I used this guide to allow Terminal to access the full disk:
https://apple.stackexchange.com/questions/372098/macos-catalina-causing-find-operation-not-permitted-errors

I executed these commands:
I first ran this command since I couldn't get around the ' Operation not permitted' errror:
rm -r ~/Library/Caches/com.microsoft.OneDrive
Didn't seem to help much.

Then ran this command after I got around that issue:
find ~/Library/Containers/ -type d -name OfficeFileCache -exec rm -r {} +

After OneDrive settled down, it's below 1 percent usage for the first time since I started using this 2012 MacBook (few weeks back). Crossing my fingers...

@ossnerjoh
Copy link

Hey Guys!
I got the same problem and this approach seems to work. Unfortunately It doesn't work on BigSur. I followed the guide es described by @horstt, but still got the "Operation not permitted" error.
Has anyone solved the problem on BigSur?
Thanks

@jianbomao
Copy link

This procedure worked for me on BigSur (Version 11.2.1) also. I was able to locate the OfficeFileCache files via Finder directly using seach in the ~/Library/Containers/ folder then move these files to the bin.
I did need to relaunch the Finder afterward to clear the high cpu on the "distnoted" process.
Will see if the issue comes back!

@Lolfm
Copy link

Lolfm commented Feb 20, 2021

This procedure worked for me on BigSur (Version 11.2.1) also. I was able to locate the OfficeFileCache files via Finder directly using seach in the ~/Library/Containers/ folder then move these files to the bin.
I did need to relaunch the Finder afterward to clear the high cpu on the "distnoted" process.
Will see if the issue comes back!

Where did you find the files?

@jianbomao
Copy link

This procedure worked for me on BigSur (Version 11.2.1) also. I was able to locate the OfficeFileCache files via Finder directly using seach in the ~/Library/Containers/ folder then move these files to the bin.
I did need to relaunch the Finder afterward to clear the high cpu on the "distnoted" process.
Will see if the issue comes back!

Where did you find the files?

In Finder go to: /Users//Library/Containers do a search for OfficeFileCache, you should see a few directories listed in the search result.

@danieldanielecki
Copy link

This procedure worked for me on BigSur (Version 11.2.1) also. I was able to locate the OfficeFileCache files via Finder directly using seach in the ~/Library/Containers/ folder then move these files to the bin.
I did need to relaunch the Finder afterward to clear the high cpu on the "distnoted" process.
Will see if the issue comes back!

Where did you find the files?

In Finder go to: /Users//Library/Containers do a search for OfficeFileCache, you should see a few directories listed in the search result.

Don't have OfficeFileCache on my Mac. I've also tried to reinstall everything by performing a complete format, as suggested by @gec118, but it didn't work either. I'm on macOS Catalina version 10.15.7. The OneDrive is such a terrible cloud for Macs...

@phhoef
Copy link

phhoef commented Apr 1, 2021

I do have the same problem.
When disabling the OneDrive Finder integration, the high cpu is reduced in some situations. When OneDrive syncs, the distnoted and OneDrive process still have high cpu for some reason.

I am syncing 2 accounts with OneDrive:

  • OneDrive for Business (Office365)
  • OneDrive Private (OneDrive.com)

The high cpu problem only occurs for the Office365 account.
Not sure, why this makes a differences.

Killing the distnoted process brings the cpu load down, but apparently this is not a good solution...

Edit:
I've disabled Files on Demand for Office365 account, and actually that seems to help.
The Finder integration is active again and the distnoted process goes not wild. Still, the OneDrive process has quite high cpu (even if it's lower), when files are syncing. But the fan spins not up and the load appears only while syncing.
It's not an ideal solution as I really like and use Files on Demand, but at least OneDrive becomes usable again ...

@danieldanielecki
Copy link

danieldanielecki commented Apr 10, 2021

Contacted the Microsoft Premier Support and the reason OneDrive has problems on Mac (and I guess not only) in my case was a higher amount of files than 300k. It was a bit strange for me, because for a looong time never had such a problem, even with node_modules in the OneDrive. Sadly, once the problems araised I've kept the setup for several months causing my battery to... die faster. Please don't do it :)

As stated here: "For optimum performance, we recommend storing no more than 300,000 files in a single OneDrive or team site library. Although SharePoint Online can store 30 million documents per library, for optimum performance we recommend syncing no more than 300,000 files across all document libraries. Additionally, the same performance issues can occur if you have 300,000 items or more across all libraries you are syncing, even if you are not syncing all items in those libraries."

The support.microsoft.com article provides the same information.

My problem was the node_modules folder. I've found a nice solution regarding Dropbox to ignore this file, but it doesn't work on OneDrive. It's also in the official help docs, as stated here: Once ignored, the file or folder remains where it is in your Dropbox folder on your computer’s hard drive, but it’s deleted from the Dropbox server and your other devices, can’t be accessed on dropbox.com, and won’t sync to your Dropbox account.

I've tried to use a similar solution Dropbox has, but then the local node_modules is being deleted, as stated here: If you uncheck a folder you are syncing to your computer, the folder will be removed from your computer. The folder and its contents will still be available online.

I've seen a couple of hacks, like here, but I've decided to simply keep my projects on OneDrive without the node_modules. Once working on the project, simply moving it towards Downloads, which isn't synchronized with any cloud. In that case, I do have to remember to git pull in the OneDrive folder to keep it synchronized. That's a backup anyway, because the source code is of course on GitHub/GitLab/etc.

@shvydky
Copy link

shvydky commented Jul 14, 2021

The only thing that really helped in my case is OneDrive Reset

@himynameisubik
Copy link

This script does not seem to fix the problem of distnoted, onedrive and onedrive finder integration going wild on my 2 macs. Despite reinstalling macos and reinstalling onedrive, the problem is still there. Only way I got it to calm down is to use AppPolice (https://github.com/AppPolice/AppPolice) and restrict these processes to 20-30% max usage.

This worked well for me after trying many other solutions. Resetting OneDrive only helped for some days and it would still come back.

(Using macOS Catalina 10.15.7)

@stevenjude
Copy link

I had this problem earlier and ran the script and it fixed it for some time. Came back again later. I then decided to search for a different approach and looked for a way to prevent Onedrive from using excess CPU. I then ran into AppPolice which does just that. I now limit OneDrive and OneDrive Finder Integration to 50% CPU and everything's fine. When i find any app that goes over the 100% limit, I then research the issue and if I find multiple users have had the cpu issue with no resolution, then I just limit that app as well. you can get AppPolice from the following link. I'm using it on Big Sur - 11.6. Hope this helps others on this post.

https://github.com/AppPolice/AppPolice

@veritymedia
Copy link

For people with crazy idle OneDrive CPU usage, you might want to try disable the auto start in OneDrive's own settings, and enable it through SystemPref -> Users&Groups -> Login Items (tab) -> + OneDrive to the list. There seems to be an issue with how OD (and Dropbox for that matter) handle their own startups. Maybe your problem is caused by that, but of course, your milage may vary. At least it's a safe method to try.

@Gu213
Copy link

Gu213 commented Nov 7, 2021

Disabling autostart in OneDrive's settings reduced the CPU load instantly and has kept low for 2 days now, few restarts. In the meantime I deleted ca. 200,000 files on the Onedrive cloud (which has been excluded from sync to the computer, however). So cannot determine which part of my scenario has been the key one, but disabling autostart within Onedrive's properties seems to help in my case. It brings no harm, so why not trying?

@DCorredorM
Copy link

DCorredorM commented Dec 1, 2021

Improved the script to kill all alive procecess regarding onedrive. If you want to reopen it you can pass ass first argument the word open and it will resatrt onedrive. Otherwise it will shut OneDrive off. This really helped me because it kills all the 'OneDrive Finder Integration' procecess that was what was overheating my computer.

## Fix OneDrive for Mac CPU usage
## 
## Seems this is still a problem 5 years later after I created this little gist.
## I have long since stopped using OneDrive (luckily), but according to
## comments below, I have added the new path for OfficeFileCache for macOS
## Mojave (10.14) and Catalina (10.15).

_open=${1:-not}

## Run this on macOS Mojave (10.14) and Catalina (10.15)
find ~/Library/Containers/ -type d -name OfficeFileCache -exec rm -r {} +

## Run this if you're on pre-Mojave (< 10.14)
find ~/Library/Group\ Containers/ -type d -name OfficeFileCache -exec rm -r {} +

# Kill one drive procecess
killall OneDrive
ps aux | grep OneDrive | awk '{print $2}' | xargs kill -9 

if [ "$_open" != "not" ]; then
	open -a OneDrive
fi

@tcutts
Copy link

tcutts commented Apr 2, 2022

High OneDrive CPU use might also be a consequence of your antivirus software's on-access scanning. I found I had huge CPU use in One Drive for the last two days, and hence found myself here. I wondered about my anti-virus (BitDefender). I switched it off temporarily, and One Drive CPU use returned to something low. I then switched BitDefender back on and OneDrive CPU use remained low. I suspect that BitDefender and One Drive syncing had got themselves into a mutually dependent loop, and switching BitDefender off broke that loop.

@drogago
Copy link

drogago commented Apr 12, 2022

In my case, I needed to reinstall all Office 365 apps. That helped for a while. I noticed that the problems returned after using software to clean my Mac. So I reinstalled it again and blocked in OneDrive all apps which can try to scan the whole storage.
I have two ideas about what may cause the problem:
First, some apps try to access all files, which creates problems. But in this situation, OneDrive should try to download all files.
So more practical is the idea that in temp files, OneDrive storage some vital information about sync status. Then cleaning apps delete the files and break OneDrive.
I am not sure if I am right. Although I reinstalled Office two weeks ago, OneDrive works correctly again from this time.

@preethamam
Copy link

preethamam commented Mar 20, 2023

I have macOS 13.2.1 and OneDrive (OD) 23.048.0305.0002 (standalone). I was tired-up of this OD for a long time since they removed the system kernel extensions support. I have over 200k files of 780 GB of data. Although, I noticed the OneDrive macOS app of 2018 was terrible with high CPU usage and memory. However, it improved over time, and after December 2021, the fileprovider (removing the system kernel extension support) messed up OD. This was the problem from the end of 2021.

I was reluctant to use OD's Files On-Demand feature on mac, as I needed them even without an internet connection. Yesterday, I reset the OD on mac, which is now on the Files On-Demand. I do not see any spike in CPU and memory usage. However, sometimes it says processing changes for an extended period of time when syncing 365 files. I will observe the behavior of Files On-Demand for some time to come up with a conclusion.

I hope this helps someone if they have a similar issue.

@emory
Copy link

emory commented Apr 30, 2023

does this manifest with extended delays in Open/Save modal dialogs with some indiciates that something is horrible wrong in XPC-space?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment