Tuesday, November 23, 2010 2:42 PM | rahel luethy | 2 comment(s)
In contrast to standard Windows keyboards, the Mac one does not have a dedicated PrtScrn key. Taking a screenshot is thus a little bit trickier on the Mac, but the utility behind the scenes is also quite a bit smarter than its Windows companion.
For the matter of completeness, the Command-Control-Shift-3 combination is the equivalent to the Windows key: it captures the complete screen and copies the PNG image to the clipboard. The service that processes this command is called SystemUIServer and it understands quite a few more shortcuts, all just modifications of the standard behavior. I spare you the details, but here are some goodies to play around with:
Cross-hair Cursor
As a side-effect of the Command-Shift-4 variant (screenshot of selected area) the mouse cursor changes to a cross-hair variant which displays the pixel-based screen coordinates. This is really handy during UI development, especially when combined with magic mouse zooming.
Capturing Individual Windows
While the cross-hair cursor is visible, pressing the Space bar will turn it into a little camera cursor which then allows capturing only the focused window. This is quite similar to the Alt-PrtScrn combination on Windows, except that you can actually move the (blue) selection at your will and only trigger the shot once you're ready.
Preview/Terminal
All commands mentioned so far either put the captured image to clipboard or save it straight to your Desktop. If you regularly want to annotate or otherwise edit your screenshots before saving them, you may prefer to trigger them from the Preview application (File » Take Screen Shot). Finally, there's also a command-line utility called screencapture, but honestly, I've never used it so far.
Tuesday, November 16, 2010 8:30 AM | rahel luethy | 2 comment(s)
One of the reasons I really love the Mac as a development machine, is the fact that it has a real terminal. As much as I appreciate the nice Cocoa GUI, the command line interface (CLI) is often the most efficient way to control files and directories, especially for bulk operations.
The default shell on Mac OS X is Bash, and it comes equipped with a variety of commands and utilities. However, the way it is initially configured on the Mac is quite disappointing. Thus, here are a few simple tweaks to improve it:
Coloring
The first weakness becomes visible after a simple "ls" command: The default Terminal is not colored. I am not referring to the simple background/foreground themes that are easily controllable from the settings, but I'd like directories to be displayed in a different color than files, symbolic links, etc. On the Mac, the best place to control bash settings is ~/.bash_profile. Open it with any editor an add the following two lines to it:
export CLICOLOR=1
export LSCOLORS=dxfxcxdxbxegedabagacad
You will then need to issue a source ~/.bash_profile for your changes to take effect — tada!
Prompt
Another simple improvement is the configuration of a better prompt (the text to the left of your blinking command line cursor). This is controlled via the PS1 environment variable (again in ~/.bash_profile). A good start could be
PS1='\u@\h:\w\$ '
Aliases
Whenever you catch yourself repeating lengthy commands, consider adding an alias configuration to ~/.bash_profile. A standard one covers the "show a long listing of all files (including hidden ones) in the current directory":
alias ll='ls -al'
Open Files & Directories
The Terminal comes with an open command which does exactly what it says on the tin (do a man open to read the fine print). The two variants I use most are open . to open a Finder window for the current directory, and open -a TextMate.app foo.txt to edit a text file in my favorite editor (no, it's not vi nor emacs). Again, this command is way too long, so I mapped it to e (like edit) in my ~/.bash_profile:
e () { open -a TextMate.app $*; }
Shortcuts
And finally, my personal faves among bash shortcuts:
Ctrl-a — go to the start of command line
Ctrl-e — go to the end of command line
Meta-f — go to next word in command line
Meta-b — go to previous word in command line
Ctrl-k — delete from cursor to end of command line
Ctrl-u — delete from cursor to beginning of command line
Arrow Up — insert previous command in history
Ctrl-r — reverse serach in history file
Meta-. — insert last argument
Don't forget to map the Terminal itself to a handy Quicksilver shortcut. As mentioned already, mine is launched via Ctrl-Esc.
Thursday, November 11, 2010 9:01 AM | rahel luethy | 0 comment(s)
This is mostly a note to myself, because every time I have to alter a JAR, it takes me way longer than it should. In essence, adding or removing files to/from an existing Java archive is not possible. The official way to go is extracting the files, changing them as needed, and re-packaging the final set. This is cumbersome and error-prone — suddenly you end-up with a different manifest, unintentionally packaged hidden system files (like .DS_Store on the Mac), or loose track of the folder hierarchies.
There is one good thing about JAR files: They are also ZIP files. Thus you can rename existingArchive.jar to existingArchive.zip and suddenly have all the zip command line tool goodness on your side:
Adding a file to a ZIP archive:
ls foo/bar/new.txt | zip -@ existingArchive.zip
Removing a file from a ZIP archive:
zip -d existingArchive.zip foo/bar/old.txt
If you just need to alter a single archive, using one of the various ZIP freeware GUIs might be even easier...
Wednesday, November 03, 2010 7:55 AM | rahel luethy | 6 comment(s)
Even though I like my slick & shiny magic mouse, I'm a keyboard person when it comes to daily computer life. As expected, a few things are different on the Mac compared to my previously used platforms (Linux & Windows) — here's my selection of the most important settings, tweaks & workarounds:
Full Keyboard Access
Let's assume that a program prompts you with a standard OK/Cancel dialog. On most platforms, such dialogs are navigable by keyboard: The Tab key switches focus between the controls and Enter triggers the selected button. Not on the Mac. For starters, full keyboard access is off by default — turn it on via System Preferences » Keyboard » Keyboard Shortcuts » Full Keyboard Access (All Controls) . In addition, the behavior is slightly different: While the Tab key works like expected, Enter fires the default button (blue) while you need to press Space to invoke the selected button (blue outline).
Terminal Alt Key
While I will probably write a separate post on Terminal issues, the most important tweak for me was the reassignment of the Meta key (Alt key on Windows). In bash, the Meta key is quite crucial: Meta-. (insert last argument) IMHO is the most useful shortcut ever. Unfortunately, Meta is emulated with the Esc key on the Mac, which is really not very ergonomic. You can however reassign it in the Terminal Settings, on the Keyboard tab ("Use option as meta key").
fn Key
The function keys (F1 to F12) are another newbie pitfall. These keys are overloaded on the Mac, F8 e.g. plays your music library in iTunes. If you intend to use them as "raw" function keys (and e.g. use F8 to drive the debugger in Eclipse), you need to hold the special fn key.
Quicksilver
One of my favorite Mac applications so far is Quicksilver, which is best described by its mantra — Act without doing. In essence, it is a smart version of Spotlight. A fully configurable application launcher/controller which is navigable by keyboard. Describing it further wouldn't do justice, so I'm just going to list my 3 favorite use cases and you can read the rest in one of the various online tutorials:
- Launching applications via keyboad. Over the last +7 years, I always launched a Terminal via Ctrl-Esc. Quicksilver does the trick on the Mac.
- Browsing directories. Quicksilver is also a smarter version of the Finder.
- Clipboard history: Maintains a (configurable) number of last clipboard entries, ready to be pasted anywhere.
I overloaded the Spotlight keyboard shortcut Ctrl-Space to trigger Quicksilver (and don't forget to say goodbye to the Dock, Finder & Spotlight before you install it, you will most likely never use them again ;-)).