A Troubleshooting Procedure that may Fix Problems with macOS El Capitan or Later
You should try each, one at a time, then test to see if the problem is fixed before going on to the next.
Be sure to backup your files before proceeding if possible.
- Shutdown the computer, wait 30 seconds, restart the computer.
- Disconnect all third-party peripherals.
- Resetting your Mac's PRAM and NVRAM
- Reset the System Management Controller (SMC)
- Reset your Startup Disk and Sound preferences, if needed, after resetting the PRAM.
- Test in safe mode to see if the problem persists, then restart normally. Use safe mode to isolate issues with your Mac and Playing Safe - what does Safe mode do?
- Repair the disk by booting from the Recovery HD. Immediately after the chime hold down the Command and R keys until the Utility Menu appears. Choose Disk Utility and click on the Continue button. Select the indented (usually, Macintosh HD) volume entry from the side list. Click on the First Aid button in the toolbar. Wait for the Done button to appear. Quit Disk Utility and return to the Utility Menu. Restart the computer from the Apple Menu.
- Repair permissions on the Home folder: Resolve issues caused by changing the permissions of items in your home folder.
- Create a New User Account Open Users & Groups preferences. Click on the lock icon and enter your Admin password when prompted. On the left under Current User click on the Add [+] button under Login Options. Setup a new Admin user account. Upon completion log out of your current account then log into the new account. If your problems cease, then consider switching to the new account and transferring your files to it - Transferring files from one User Account to another.
If you get to here without a fix, then you need to think about doing an erase and Install. This means a full backup of your files, and you will need a copy of the full High Sierra Installer which may prove difficult if your computer supports Catalina.
The problem with random shutdowns is tracking it down. You could just have a disk drive with a bad sector or it could be a malfunctioning memory module. If the shutdowns are due to kernel panics, then posting a copy of the kernel panic log would help. You will find that in /Library/Logs/ folder or the /Home/Library/Logs folder. There are several sub-folders, and I don't know where to find it, so you will need to do some searching. If one is not found, then the shutdown is not caused by a kernel panic or due to the timing a log could not be created.
Another possibility is over-heating causing one of the processors to shutdown in order to prevent damage. If you were doing something at the time which could have caused extreme heat generation, then that may be the source of the problem. You might try replicating the situation just before the shutdown occurs, and monitoring with Activity Monitor.
Use Activity Monitor to Kill Runaway Processes
Use Activity Monitor on your Mac
Runaway applications can shorten battery runtime, affect performance, and increase heat and fan activity.
I have an iMac like yours but never had a problem of random shutdowns. I note that you run an awful lot of third-party software, extensions, etc., anyone of which could cause shutdowns because of an incompatibility. Running in Safe Mode should prevent them from running. If the random shutdowns stop, then start looking at all the software that isn't loaded when in safe mode.
About Using Safe Mode