terminal

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 MacOS 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.)

A sample MacOS Bash startup file (.bash_profile)

In case you need a sample .bash_profile startup file for your MacOS or other Unix/Linux system, I thought I’d share my most recent version here.

If you're not familiar with a .bash_profile file, this is a startup file that is read whenever you open a new Terminal window. It's a special configuration file, and it needs to be placed in your home directory. For instance, on my MacBook Pro, this file is located as /Users/al/.bash_profile.

Mac OS X debug tip - Check the log files

Mac OS X debug FAQ: Help, I'm having a problem with [fill in the blank] on my Mac OS X system, how do I troubleshoot it?

I just ran into a problem when trying to create a Safari web clip dashboard widget, where the web clip isn't properly updating itself, and I stopped for a moment to think about how to troubleshoot/debug this Mac OS X problem. That's when I thought, "Okay, a Mac is a Unix system, check the log files." So I cracked open a Mac Terminal window, and checked the system log file:

How to use Spotlight to search for files from a Mac OS X Terminal window

If you ever want to use the Spotlight search functionality from a Mac OS X terminal window, you can access the same Spotlight information using the mdfind command. Here are a few examples of how to use mdfind to find files and directories on your Mac OS X system.

To find files with the word "alexander" in them, from a Terminal window you can use mdfind like this:

mdfind alexander

Now, if you just want to find a file using a portion of the filename, use this mdfindcommand: