Mac Tips

Tips, Tricks, and Miscellany for Macintosh Computing
by Oliver; 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

Turn on FileVault

As the docs say, "FileVault secures the data on your disk by encrypting its contents automatically". Go to:
System Preferences > Security & Privacy > FileVault
to turn it on.

Require a Password to Wake Your Mac from Sleep

Go to:
System Preferences > Security & Privacy > General
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

If you're using the terminal, you'll want to set up your dotfiles. You can read more about the subject 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.

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.

Use Firefox Profiles; Run Multiple Copies of Firefox with Different Profiles Simultaneously

It's useful to have multiple web browsers. For example, sometimes you might want a browser with saved email login credentials and sometimes you might not. To accomplish this, you could use Chrome for email and Safari for other stuff. But one of the neat things about Firefox is that you can do this with a single brower. You need only create different user profiles. As the docs say, "Firefox stores information about your settings, preferences, and other user items in your user profile". Here's what they look like:

image

It gets even better. As outlined here, you can run multiple copies of Firefox with different profiles simultaneously. From the command line, run:
$ cd /Applications/Firefox.app/Contents/MacOS
$ ./firefox -ProfileManager -no-remote

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

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.

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.

Run a Dev Server Out of Any Folder On Your Mac

Via lifehacker: simply navigate to a directory in the terminal and run:
$ python -m SimpleHTTPServer 8080
By 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.

python3
In Python 3, the syntax is slightly different:
$ python3 -m http.server 8080

iPhone: Save your Text Messages, Contacts, Etc. in Text Files

If you have an iPhone, you can save your text messages, contacts, etc. in text files as outlined in this tutorial.

Update: It seems that webpage no longer exists. Here it is, reproduced without permission:

Digital Forensics

iPhone Forensics
Retrieve text messages, notes, call history etc from a backup file
It is possible to retrieve almost all the information stored on an iPhone from the backup file. You cannot retrieve stored music (as it is not backed up), or wifi passwords (as they are only stored on ecrypted backups). See Apples' Knowledge Base for more information.

The backup files are stored in the following places:
    
        
Operating System Backup Location
Windows \Users\(username)\AppData\Roaming\Apple Computer\MobileSync\Backup\
Windows XP \Documents and Settings\(username)\Application Data\Apple Computer\MobileSync\Backup\
Mac ~/Library/Application Support/MobileSync/Backup/
The backup folder is a long hexadecimal name unique to each device. Within the folder are lots of hexadecimal files, which are consistant for all devices. Some important databases are listed:
    
        
Contents Real Name Backup Name
SMS Messages sms.db 3d0d7e5fb2ce288813306e4d4636395e047a3d28
Call History call_history.db 2b2b0084a1bc3a5ac8c27afdf14afb42c61a19ca
Contacts AddressBook.sqlitedb 31bb7ba8914766d4ba40d6dfb6113c8b614be442
Notes notes.sqlite ca3bc056d4da0bbf88b5fb3be254f3b7147e639c
The above are stored as SQLite3 databases, so you will need an SQLite viewer to see their contents

Photos and other files are stored individually, and all you need to do is add a .jpg extension onto a photo file and you will be able to view it.

Settings and other details are often stored in Apple's Property List format. These need to have a .plist extension and can be viewed these with a PList viewer
Manipulating the files
There are good reasons to manipulate these files - perhaps you want to filter 10,000 text messages to find those sent on a certain date, or to delete all messages older than a year to save space on your own device. One good way of doing this is to use the Python programming language.

Download Python from the downloads page and install it. Note that Python 2 and Python 3 versions are somewhat different in style and syntax (Python 3 is not "better" or newer than Python 2) so choose one you are comfortable with (I use Python 2 here). When you install Python in Windows, you have the option to add the executable to your PATH environment variable. I recommend you check this, so you can run Python from any location using the command line. You can run Python in Windows using the Command Prompt (Start - All Programs - Accessories)

Happily Python already comes installed with a SQLite module sqlite3, and is made available by a binding called pysqlite. However, you may not have the latest version of the SQL Database Library. This may cause the misleading error message:
sqlite3.DatabaseError: file is encrypted or is not a database
Check which version you have installed with Python in the command prompt
C:\Python27\>python
Python 2.7.8 ...[some info]
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.6.2'
>>>


In my case, version 3.6.2 is not up-to-date enough to open the sms.db file, though it will open notes.sqlite without any issues.

To solve this, download the latest version from sqlite.org, either build it yourself, or copy the precompiled binary (sqlite.dll) to your Python DLL folder (in my case C:\Python27\DLLs), and confirm:
>>> sqlite3.sqlite_version
'3.8.5'
>>>


Now I can open the sms.db correctly.
The SMS database - sms.db
In Python, you must import the module, connect to the database, set the 'cursor' position, then use the execute command to run SQLite commands. Then use fetchone() or fetchall() to return the row(s). For example:
import sqlite3
connection = sqlite3.connect("sms.db")
with connection:
    cur = connection.cursor()
    cur.execute("SELECT ROWID,date_delivered,text FROM message")
    rows = cur.fetchall()

for result in rows:
    print result
Now if you have a lot of messages, the above code could be running for a while, and it may not be very useful. To get something a bit more meaningful, we can examine the way messages are stored on iOS. There are lots of tables, here are a few of them (I haven't written all the fields, just some of the useful ones):
    
        
Table Name Fields
message ROWID, guid, text, service_center, subject, date_read, date_delivered,...many more
attachment ROWID, guid, account_id, account_login, display_name,...more
Contacts ROWID, guid, created_date, filename, mime_type, is_outgoing, user_info,...more
These ones are only really used to join tables:
    
        
Table Name Fields
chat_handle_join chat_id, handle_id
chat_message_join chat_id, message_id
message_attachment_join message_attachment_join message_id, attachment_id
So there is a lot of information available, you will most likely want to select just a few relevant bits and join your own tables to present the data how you wish.
See this page for how to parse the db.
Advertising

image


image