Mac Tips

Tips, Tricks, and Miscellany for Macintosh Computing
by Oliver; Dec. 9, 2014
mac
     

Hear ye! Hear ye! Tips for Macintosh computing.

Use Hot Corners and Keyboard Shortcuts

Turn on Hot Corners in:
System Preferences > Mission Control
I like to use:

image

Use keyboard shortcuts via:
System Preferences > Keyboard > Shortcuts
In particular, I like to map Option left to "Move left a space" and Option right to move right:

image

Require a Password to Wake Your Mac from Sleep

This is a good policy to ensure people don't tamper with your computer if you leave it idle. Go to:
System Preferences > Security & Privacy
And require a password a few minutes after sleep or screen saver begins.

Install iTerm2

iTerm2 improves on the ordinary terminal and makes it easy to set up key-bindings for shortcuts. In particular, I like to map Control left to jump word left and Control right to jump word right. To do this, check your terminal preferences to see how it treats Control left and Control right:

image

Here, it's Esc [5C and Esc [5D so executing:
# make cursor jump over words
bind '"\e[5C": forward-word'	# control+arrow_right
bind '"\e[5D": backward-word'	# control+arrow_left
in the shell will accomplish this. On OS 10.9.5 and up, it seems to be slightly different:

image

For this, use:
bind '"\e[1;[5C": forward-word'		# control+arrow_right
bind '"\e[1;[5D": backward-word'	# control+arrow_left
In any case, check your terminal preferences and proceed accordingly. For a more thorough explanation, read about keyboard shortcuts, readline functions, and key bindings here.

Install brew

brew calls itself, "The missing package manager for OS X" and that's about right. Download brew to install things with ease from the command line (it's far superior to its rival, macports). As the homepage notes, here's how to get it:
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install wget

wget downloads stuff from the web via the command line. Get it with brew:
$ brew install wget

Install the Command Line Developer Tools

At some point in the recent past, Apple decided to become authoritarian and horrible and stopped including basic tools, like gcc, with Macintosh. To get the so-called command line developer tools, I remember having to formally register as a developer with Apple—as if I were a sex offender in a school zone! They came bundled with Xcode. This blog post describes various ways you can get your hands on the developer tools. If your OS is up to date, it should prompt you to download them when you install brew.

Install the GNU Coreutils

The GNU Coreutils are the lifeblood of the command line. Macintosh has its own version of them but, annoyingly, many of the commands behave differently (e.g., readlink) or don't exist (e.g., seq). So don't mess around and get the GNU ones posthaste. The easiest way to get them is with brew:
$ brew install coreutils
Don't forget to update your PATH so the coreutils binaries come before your Mac's (brew will prompt you to do this). Read more about putting the coreutils on a Mac.

Install tmux

tmux is an awesome terminal multiplexer, which is superior to the built-in GNU screen utility. If you're using tmux and you accidentally quit or close your terminal, you'll be able to reaccess your specific terminal sessions and programs you were running won't have aborted. That's because tmux has accomplished the neat trick of decoupling your command line sessions from a specific running instance of your shell. Download it with brew:
$ brew install tmux
Read more about how to use tmux, as well as how to set up your tmux.conf configuration file, here.

Set up your .bash_profile, .bashrc, and Other Dotfiles

To set up your dotfiles, clone mine via GitHub. You can read more about the subject of dotfiles here. One note: on Macintosh, when you open up a new shell, this happens automatically:
$ source ~/.bash_profile
To underline this point, your .bash_profile, not your .bashrc, gets sourced.

Generate ssh Keys

If you're planning to ssh, you'll want to generate ssh keys:
$ cd ~/.ssh
$ ssh-keygen -t rsa
Read more about the process here.

Install VLC

VLC is a great, free video player. Read about all its cool features:
10 Useful Features Hidden in VLC, The Swiss Army Knife of Media Players
25 things you can do with VLC Media player!

Install youtube-dl

Ever wanted to download a YouTube video? youtube-dl makes it easy. Again, you can get it with brew:
$ brew install youtube-dl

Install Imagemagick

Imagemagick is an awesome tool suite for manipulating images, in all sorts of ways, from the command line. Get it with brew:
$ brew install imagemagick
Read my guide to simple Imagemagick commands.

Install gpg

Install gpg for encrypting stuff:
$ brew install gpg
I have a short gpg tutorial here.

For Python Developers: Install pip and virtualenv

pip is the python package manager. Follow the instructions and first download get-pip.py:
$ wget https://bootstrap.pypa.io/get-pip.py
Then install it:
$ sudo python get-pip.py
Install virtualenv:
$ sudo pip install virtualenv
Install python3:
$ brew install python3

Download Tor

Data collection is big business nowadays. Every company wants to know exactly who you are and exactly what you're doing on the internet. Advertisers pay for databases rich with granular information about people's habits, political views, shopping tendencies, dating profiles, etc. Using Tor, an open source IP anonymizer, can help thwart this. As Tor's homepage says, "Tor is NOT all you need to browse anonymously! You may need to change some of your browsing habits to ensure your identity stays stafe." Tor doesn't support some things—for example, as of this writing, you can't watch most video (including YouTube) on Tor. To state the obvious, most services that require a user account are out of bounds with Tor and Gmail simply won't allow it—seeming to say, No free email if you don't tell us your IP.
Read about Tor on Wikipedia.

ssh into Your Mac

To ssh into your Mac, go to:
System Preferences > Sharing
and turn on Remote Login:

image

copy the ssh address, as it's given in the window (I've censored mine). A word of caution: ssh is safe, but I wouldn't leave this option on, unless you have a good reason.

Tip: If you turn on Remote Login, you can copy files onto your Mac directly over the internet, sans hard drive, with rsync.

What to Do if The Dock, Spaces, The Finder, or Another Program Crashes

You can force quit a program, by invoking Command-Option-Esc. As this page instructs, if the Dock or Spaces fritzes out, try:
$ killall -KILL Dock
If the Finder crashes:
$ killall -KILL Finder
If the menubar crashes:
$ killall -KILL SystemUIServer

How to Retrieve Passwords Saved on Your Computer

Suppose you forgot the password to an email account, but you know it's saved in Chrome. How would you retrieve it? Go to:
Applications > Utilities > Keychain Access
Find the service corresponding to your password, click on it, and then check Show Password. You'll need to type in your Mac's account password to see it.

Take a screenshot

To take a screenshot, press Command-Shift-3. You can also use the program Grab in the Utilities folder.

Video Screen Capture (i.e., Record Your Computer Screen)

You can record your screen with QuickTime versions greater than 10. The steps are given in this post. To quote verbatim:
  1. In QuickTime Player, choose File > New Screen Recording.
  2. Choose options for the screen recording from the arrow pop-up menu.
  3. Arrange the computer windows as you want to capture them, and then click the Record button.
  4. To stop the recording, click the Stop button, or press Command-Control-Escape.
If you want a commercial program that does this, I hear good things about ScreenFlow, although I've never used it.

Make Your Macintosh Speak

Macs come with a command line utility, say, that makes your computer speak:
$ say "hello world"
(ideal for ordering co-workers around:)

You can also read a whole file. Suppose the file juicy.txt is:
It was all a dream
I used to read Word Up magazine
Salt'n'Pepa and Heavy D up in the limousine
Hangin' pictures on my wall
Every Saturday Rap Attack, Mr. Magic, Marley Marl
I let my tape rock 'til my tape pop
Smokin' weed and bamboo, sippin' on private stock
Way back, when I had the red and black lumberjack
With the hat to match
Then:
$ say -f juicy.txt --progress -r 400 -v "Fred"
specifies we want the voice "Fred" to read it at 400 words per minute.

Listen to Thousands of Channels on Free Internet Radio

There are thousands of free radio stations at your fingertips in iTunes. Simply navigate to the Internet Radio section:

image

Make Files or Folders Invisible

Another Mac-specific command line utility is SetFile, which is used for setting file attributes. One neat thing you can do with this is to make files invisible in the GUI:
$ SetFile -a V myfile # make myfile invisible in the GUI
$ SetFile -a v myfile # make myfile visible in the GUI

Encrypt a Folder on Your Mac

There's a nice tutorial on how to encrypt your folder as a disk image here. To summarize, open the program:
Applications > Utilities > Disk Utility
Navigate via menu to:
File > New > Disk Image from Folder
Choose the folder you want to encrypt and select the options:
  • Image Format: read/write
  • Encryption: 256-bit AES encryption
At this point, you'll be prompted for a password:

image

Make sure to uncheck the 'Remember password' box. Once the image has been created, throw away the original folder using 'Secure Empty Trash' or shred on the command line. Now you'll need a password everytime you try to mount your .dmg file (i.e., open the folder).

If you simply want to encrypt a text file, you can do that with the command line utility gpg, as I discuss here.

Check When Your Files Were Last Accessed; Check When Your Computer Was Last On

To check when your files were last accessed in the GUI, open up a folder, click on the action wheel, and select:
Show View Options
That should pop up a window that looks like this:

image

Choose Date Last Opened and sort your files by that attribute. Alternately, on the command line you can use the utility mdls:
$ mdls myfile.txt
which "lists the metadata attributes for the specified file". If the metadata contains a field like ItemLastUsedDate, you have your answer. Files traditionally have 3 time stamps stored in the metadata: the last access date, the last modify date, and the birth date. Another way to get at this information is with the unix utility stat:
$ stat myfile.txt
I'm not an expert on these commands, but by playing with them a bit I've found that the mdls access time stamp does not get updated if you access the file on the command line (say, with cat), and only reflects file access from the GUI. In contrast, the stat access time reflects command line activity.

One way to see when your computer's been on—and sometimes to glean information about what programs have been run—is to examine the system logs:
$ syslog | less
You can see more log files in the path:
/var/log/

Mount Your Mac Laptop onto Your Mac Desktop as an External Drive

Connect your laptop to your desktop using, say, the FireWire or Thunderbolt ports. Boot your laptop holding down the t key, as described here. Your laptop hard drive should mount as a volume on your desktop.

Burn a Linux Image onto a CD

Download an .iso of your favorite linux distribution—e.g., Ubuntu. Burn it onto a CD with Mac's Disk Utility app. Insert the CD into a computer and boot off of it. Welcome to Linux!

Copy a DVD

There's a post detailing how to copy a DVD onto your Mac or another disc here. In short, you open the Disk Utility, choose the New Image option, and select DVD/CD Master as the image format. This creates a .cdr file, which you can watch on your computer or burn to another disc.
Advertising

image


image


image


image