terminal

How to copy text from the MacOS Terminal to the clipboard

If you ever need to copy text (or a text file) from the MacOS Terminal to the Mac clipboard, I can confirm that the Mac pbcopy command works. It reads from STDIN and copies the text to the clipboard, so commands like these work:

$ echo "foo bar baz" | pbcopy

$ cat /etc/passwd | pbcopy

How to jump to a screen location using a mouse click with iTerm2?

When using iTerm2, if you’re editing a file with vim and want to jump to a specific location in the file using a mouse click, just hold down the [Option] key when you do a normal left mouse click. That will take you to the location directly under the mouse cursor. (Unless the mouse cursor is beyond the end of the line. In that case the text cursor will be moved to the end of that line.)

I mention vim here because I just learned about this when using vim, but you should be able to use this with any app when using iTerm2. This is an iTerm2 feature (not a vim feature).

Useful Mac OS X keystrokes (that I can't seem to remember) alvin August 18, 2014 - 12:18pm

Mac OS X keystrokes that I use fairly often, but can’t seem to remember.

How to kill/disable the Dashboard in Mac OS X 10.9

OS X 10.9 is sucking the life out of my old Mac, a 2008 iMac. Like turning off everything on Star Trek’s Enterprise so you can give power to something else (like the engines or shields), I keep looking for ways to bring a little life back to it. One way I’ve read about is to kill the Dashboard on 10.9.

You can kill the Dashboard with this Mac OSX defaults command, issued in a Mac Terminal window:

Setting the Mac Terminal titlebar to the current working directory

I often work with multiple Mac Terminal tabs open, and as a result I like to set the title in the titlebar to whatever I’m working on in each tab (such as “MONGO” or “PLAY”), so I wrote a little script named settitle to let me set the title in the titlebar from the Unix command line.

More recently I realized I was often setting the title to the uppercase version of the current directory. I came up with this command pipeline (I like to call them “mashups”) to do easily do that:

How to set the Mac OS X Terminal title | Mac Terminal titlebar

I like to set the title (titlebar) on the Mac OS X Terminal application so I can tell one tab from another. For instance, I may have the Play Framework running in one tab, SBT in another, Git in another, etc. Setting the title on each Terminal tab makes my life a little easier.

To set the Terminal title, I use a script I’ve named settitle:

Emptying the Mac OS X trash from the command line

When using a Mac OS X computer, it's easy to forget that it's just Unix running under the hood ... until your iMac graphics card dies and all you can do is use single-user mode, which has no GUI ... then you're reminded very quickly that it's all just Unix.

Take emptying the trash, for instance. Graphically, you right-click the Trash Can icon, then select the Empty menu option. From the Mac command line (Terminal) you just do this:

rm -rf ~/.Trash/*

It's funny how simple that is from the command line.

How to run a Unix shell script from the Mac Finder

If you ever want to create a Unix shell script that you can give to someone else so they can double-click it and run it through the Mac OS X Finder, all you have to do is (a) name the file with the ".command" extension and (b) make it executable. So, just name your Mac/Unix script like this:

ShowProcesses.command

Then make it executable, like this:

chmod +x ShowProcesses.command

You can also leave out the usual #!/bin/sh part on the first line.

How to restart Mac OS X networking from the command line

I've been having a problem with my MacBook Air (running Mac OS X Lion) and my wireless router, so today I decided to write a script to restart the OS X wireless networking service from the command line. In short, I use this OS X command to turn off the Mac networking service:

sudo ifconfig en0 down

and I use this command to turn the Mac wireless network service back on:

sudo ifconfig en0 up

(I found these commands on the website I linked to.)