Monday, June 12, 2017

caffeinate command: Disable Sleep on a Mac from the Command Line

What is the ‘caffeinate’ Command in Mac OS X

The 'caffeinate' command just prevents sleep entirely, but you can modify the command with various flags to prevent just the display from sleeping, provide a specified time to avoid sleeping, prevent sleeping while a command runs, and more. The command details is given below:
caffeinate command on Mac OSX
caffeinate command help

A few useful examples are discussed below.

How to Disable Sleep with the ‘caffeinate’ Command in Mac OS X

To temporarily disable sleep functions regardless of sleep settings, run the following command from Terminal in Mac OS X:
caffeinate
At the core basic function of the command, caffeinate is all that’s necessary, and while caffeinate is active sleep will be prevented until it’s no longer running.
To stop caffeinate and return to normal sleep behavior, you can hit “Control+C” to quit out of caffeinate as it’s running like this, or you can kill it with the ‘killall caffeinate’ command if desired.
You can also run caffeinate for a pre-determined amount of time to prevent sleeping for a specified block of time, say for 4 hours while you download something, and then run it in the background by adding & to it:
caffeinate -t 144000 &
The number attached to the -t flag is the amount of time in seconds for sleep to be disabled on the Mac.
Caffeinate can also be attached to other commands to prevent the Mac from sleeping while that given command runs:
caffeinate [command_to_run] -arguments
That causes the Mac to avoid sleep only as long as it takes to run the command provided, after which the normal sleep rules apply. 
With these latter tricks, if you run caffeinate in the background and want to cancel it then the easiest way to quit the process is to issue the kill command for the reference process ID, or simply ‘killall caffeinate’
To use the caffeinate command you’ll need to be running a fairly modern version of OS X, as the feature was introduced in 10.8 Mountain Lion and persists through 10.9 Mavericks, and into 10.10 Yosemite.

source: http://osxdaily.com/2012/08/03/disable-sleep-mac-caffeinate-command/

Sunday, June 11, 2017

Install node.js using NVM and Homebrew on Mac OS X

Reference: http://dev.topheman.com/install-nvm-with-homebrew-to-use-multiple-versions-of-node-and-iojs-easily/
Less than a month ago, iojs was released (multiple releases followed) and 6 days ago, the v0.12.0 of node was released.
I still had the same v0.10.x (can’t remember the patch 🙂 ) of node on my computer I installed a few months ago … As a nodejs developer, I decided it was time to get rid of my old version and switch to nvm so that I could test my projects (websites and node modules) on different engines and versions – moreover not to be stuck in the case some module should only work on one or an other …
This post is more a reminder for future me when I’ll make the install again, though it could help some people.
First, you’ll need Homebrew. If you’re a MacPorts user (or a Linux user), I assume it’s nearly the same, you may even have your own way which is faster and better, no need to troll 😉 – for Windows users, you have some alternatives.
Start by :
brew update
brew install nvm
mkdir ~/.nvm
nano ~/.bash_profile
In your .bash_profile file (you may be using an other file, according to your shell), add the following :
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh
Back to your shell, activate nvm and check it (if you have other shells opened and you want to keep them, do the same) :
source ~/.bash_profile
echo $NVM_DIR
Now, you can install node :
nvm install 0.12
From now on, you’re using the v0.12.x of node on this shell, you can install your global dependencies such as grunt-cli (they will be tied up to this version of node).
You may want to install other versions, just do :
nvm install 0.10
nvm install iojs
...
You’ll have to npm install -g your global dependencies for each version.
Switch of node version with nvm use 0.10 (more infos here).
To have a node activated by default (not to have to nvm use on each new shell), run this (stable being the id of the version):
nvm alias default stable
Now, you can run multiple versions of node on your computer.
Sources :