With launch daemons and launch agents, you can control the services that start up when you boot your computer. Launchctl lets you interact with the OS X init script system, launchd. To see more options, type screencapture -help 5. Select a portion of the screen with your mouse, capture its contents, and save the image as a pdf: $ screencapture -s -t pdf image.pdf Select a window using your mouse, then capture its contents without the window’s drop shadow and copy the image to the clipboard: $ screencapture -c -WĬapture the screen after a delay of 10 seconds and then open the new image in Preview: $ screencapture -T 10 -P image.png Here are just a few different ways you can use screencapture:Ĭapture the contents of the screen, including the cursor, and attach the resulting image (named ‘image.png’) to a new Mail message: $ screencapture -C -M image.png It’s similar to Grab.app and the keyboard shortcuts cmd + shift + 3 and cmd + shift + 4, except it’s far more flexible. Screencapture lets you take many different kinds of screenshots. You can also turn off indexing entirely with mdutil -i off. If Spotlight isn’t working the way it should, mdutil -E will erase the index and rebuild it from scratch. The mdfind database should stay up to date in the background, but you can also troubleshoot it (as well as Spotlight) using mdutil. For instance, the -onlyin flag can restrict the search to a single directory: $ mdfind -onlyin ~/Documents essay Mdfind comes with a few conveniences that make it stand out from its big blue brother.
That includes the ability to search inside files and metadata. Anything Spotlight can find, mdfind can find too.
So why not tap into its power from the command line? There’s always the venerable UNIX find command, but OS X comes with its own killer search tool: Spotlight. Many a Linux power user has tried to use locate to search for files on a Mac and then quickly discovered that it didn’t work. You can easily capture the contents of a file: $ pbcopy > tasklist.txt …will copy a list of files in your home directory to the OS X clipboard. Of course, you could also just use your mouse-but the real power of pbcopy and pbpaste comes from the fact that they’re UNIX commands, and that means they benefit from piping, redirection, and the ability to be in scripts in conjunction with other commands. These two commands let you copy and paste text from the command line. Remember that the integration between Finder and Terminal goes both ways – if you drag a file from Finder into a Terminal window, its full path gets pasted into the command line. This is especially useful for bringing up the current directory by typing open. Running open on a directory will take you straight to that directory in a Finder window. You can set the -a flag to choose the app yourself, or -e to open the file for editing in TextEdit.
open screenshot.png on an image will open that image in Preview. If you point open at a file instead, it will try to load the file with its associated GUI application. …will launch Safari as if you had double-clicked its icon in the Finder. For instance, typing: $ open /Applications/Safari.app/ Exciting, right? But it really does come in handy as a command-line double-click. Open opens files, directories and applications. Update: Thanks to reader feedback, I’ve written about a few more commands in a follow-up post: (And eight hundred more). Learning about these Mac-only programs can make you more productive on the command line and help you bridge the gap between UNIX and your Mac. But power users often aren’t aware that OS X comes with a number of its own text-based utilities not found on any other operating system. If you’re migrating from Linux, you’ll find many familiar commands work the way you expect. The OS X Terminal opens up a world of powerful UNIX utilities and scripts.