OS X Screen Recording and Converting to GIFs with free tools

One of the unknown features of newer versions of QuickTime (at least on OS X) is the ability to record videos (Arguably, QuickTime Player is misleading as a name), either from a connected camera or from the screen. Click File > New Screen Recording to bring up the recorder. If you want, select "Show Mouse Clicks in Recording".

After you're done recording, you can do some trimming right in QuickTime as well - Edit > Trim.
Now you have a QuickTime file - great, but the point is to create an animated GIF from it. For that, we'll use two free tools: ffmpeg and gifsicle. Since we're on OS X, homebrew will do the heavy lifting for us.

brew install ffmpeg
brew install gifsicle

With both installed, we can now convert the video:
ffmpeg -i MyRecording.mov -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > MyRecording.gif
Since I want to do this often, I've added a shell command to my .zshrc:

function movtogif {  if [[ $# = 0 ]]
  then 
    echo "USAGE: movtogif filename.mov"
  else 
    ffmpeg -i bash -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > bash:r.gif 
  fi 
}

For reference, the :r means to take the file path without extension. See the manpages of ffmpeg and gifsicle for more information about the parameters.

Thanks to Alex Dergachev for the original idea.