by Oliver; 2014-12-09
Hear ye! Hear ye! Tips for Macintosh computing.
Use Hot Corners and Keyboard ShortcutsTurn on Hot Corners in:
System Preferences > Mission ControlI like to use:
Use keyboard shortcuts via:
System Preferences > Keyboard > ShortcutsIn particular, I like to map Option left to "Move left a space" and Option right to move right:
Require a Password to Wake Your Mac from SleepThis is a good policy to ensure people don't tamper with your computer if you leave it idle. Go to:
System Preferences > Security & PrivacyAnd require a password a few minutes after sleep or screen saver begins.
Install iTerm2iTerm2 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:
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_leftin the shell will accomplish this. On OS 10.9.5 and up, it seems to be slightly different:
For this, use:
bind '"\e[1;[5C": forward-word' # control+arrow_right bind '"\e[1;[5D": backward-word' # control+arrow_leftIn 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 brewbrew 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 wgetwget downloads stuff from the web via the command line. Get it with brew:
$ brew install wget
Install the Command Line Developer ToolsAt 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 CoreutilsThe 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 coreutilsDon'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 tmuxtmux 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 tmuxRead 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 DotfilesTo 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_profileTo underline this point, your .bash_profile, not your .bashrc, gets sourced.
Generate ssh KeysIf you're planning to ssh, you'll want to generate ssh keys:
$ cd ~/.ssh $ ssh-keygen -t rsaRead more about the process here.
Install VLCVLC 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-dlEver wanted to download a YouTube video? youtube-dl makes it easy. Again, you can get it with brew:
$ brew install youtube-dl
Install ImagemagickImagemagick is an awesome tool suite for manipulating images, in all sorts of ways, from the command line. Get it with brew:
$ brew install imagemagickRead my guide to simple Imagemagick commands.
Install gpgInstall gpg for encrypting stuff:
$ brew install gpgI have a short gpg tutorial here.
For Python Developers: Install pip and virtualenvpip is the python package manager. Follow the instructions and first download get-pip.py:
$ wget https://bootstrap.pypa.io/get-pip.pyThen install it:
$ sudo python get-pip.pyInstall virtualenv:
$ sudo pip install virtualenvInstall python3:
$ brew install python3
Download TorData 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 MacTo ssh into your Mac, go to:
System Preferences > Sharingand turn on Remote Login:
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 CrashesYou can force quit a program, by invoking Command-Option-Esc. As this page instructs, if the Dock or Spaces fritzes out, try:
$ killall -KILL DockIf the Finder crashes:
$ killall -KILL FinderIf the menubar crashes:
$ killall -KILL SystemUIServer
How to Retrieve Passwords Saved on Your ComputerSuppose 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 AccessFind 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 screenshotTo 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:
- In QuickTime Player, choose File > New Screen Recording.
- Choose options for the screen recording from the arrow pop-up menu.
- Arrange the computer windows as you want to capture them, and then click the Record button.
- To stop the recording, click the Stop button, or press Command-Control-Escape.
Make Your Macintosh SpeakMacs 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 matchThen:
$ 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 RadioThere are thousands of free radio stations at your fingertips in iTunes. Simply navigate to the Internet Radio section:
Make Files or Folders InvisibleAnother 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 MacThere's a nice tutorial on how to encrypt your folder as a disk image here. To summarize, open the program:
Applications > Utilities > Disk UtilityNavigate via menu to:
File > New > Disk Image from FolderChoose the folder you want to encrypt and select the options:
- Image Format: read/write
- Encryption: 256-bit AES encryption
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 OnTo check when your files were last accessed in the GUI, open up a folder, click on the action wheel, and select:
Show View OptionsThat should pop up a window that looks like this:
Choose Date Last Opened and sort your files by that attribute. Alternately, on the command line you can use the utility mdls:
$ mdls myfile.txtwhich "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.txtI'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 | lessYou can see more log files in the path:
Mount Your Mac Laptop onto Your Mac Desktop as an External DriveConnect 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 CDDownload 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 DVDThere'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.
Run a Dev Server Out of Any Folder On Your MacVia lifehacker: simply navigate to a directory in the terminal and run:
$ python -m SimpleHTTPServer 8080By default, this will look for a file named index.html and you'll see the result at:
http://localhost:8080(or http://0.0.0.0:8080 or http://127.0.0.1:8080). This is a great way to mock up a website for testing on your local machine before you publish it to the world.
In Python 3, the syntax is slightly different:
$ python3 -m http.server 8080