Category Archives: Mac and OSX

Prevent external HDD drives from sleeping on Mac OSX

I have 4TB of data stored in three external hard-drives attached to my mac. It’s very frustrating when these HDDs enter sleep and the operating system hangs until they wake up, even for actions which do not involve them.

So, putting the side-effect of possible sooner failure due to wear aside, I wrote a little bash script to touch a file on every drive and set this script to run every 5 minutes via cron.

I’ll probably optimize it a little by disabling it every day during daytime hours (when I’m not at home).

This is the bash script

for D in /Volumes/*; do
    if [ -d "${D}" ]; then
        echo "${D}"
		touch "${D}/.touchdrive"
    fi
done

And this is the crontab entry for it

*/5 * * * *   sh /touchDrives.sh > /touchDrivesCron.log

 

How to format C and C++ code in Sublime Text

I am writing some C code on my mac using Sublime Text and I needed a quick way to format the code for better readability.

I found this package for Sublime Text named SublimeAStyleFormatter: https://packagecontrol.io/packages/SublimeAStyleFormatter

I’ve installed it with git by going on the packages folder and cloning the git repo:

cd ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/
git clone git://github.com/timonwong/SublimeAStyleFormatter.git

And that was it! I can format my C code by pressing Ctrl + Alt + F.