Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Another way to create quick-access SSH shortcuts UNIX
I was initially using SSH shortcuts as described in this hint, but after using the hint for a while, I noticed some problems:
  • There doesn't seem to be a way to create .inetloc files other than drag and drop. You can create a file that has the correct data fork and the Finder will handle it, but without the resource fork portion that the Finder itself creates upon drop, other programs (like Path Finder) won't open the file properly. I keep a list of hosts I regularly connect to in ~/.hosts, and I wanted to be able to use a script to create the .inetloc files based on .hosts, rather than have to drag and drop the location to the Finder for every single one. (That would be fine if it was one time only, but the list changes.)
  • For whatever reason (I suspect a bug in, if you open a new Terminal window via one of these ssh://host shortcuts, .term files will not open until you relaunch the Terminal. They'll make Terminal the active pplication, but nothing happens.
  • For whatever reason (another bug?), windows opened via the ssh://host .inetloc files don't show the "Command key" (⌘1, ⌘2, etc) in the window's title bar. (Although the command keys still work if you're a good guesser.)
  • The ssh:// addresses don't allow for many SSH options. From what I can tell, username is the only thing you can change, and even that can be problematic as robg pointed out.
  • I had to tell QuickSilver where to look for the .inetloc files, but I noticed that it already indexes ~/Library/Application Support/Terminal/ by default.
The solution was to use .term files for everything instead of ssh:// shortcuts.
read more (287 words)   Post a comment  •  Comments (18)  
  • Currently 2.00 / 5
  You rated: 2 / 5 (4 votes cast)
[13,165 views]  View Printable Version
10.4: Find potential duplicate files via Spotlight metadata UNIX
I often rename files immediately after downloading and stick them in a folder somewhere for later reference. But I also often forget what I've already downloaded. So I wrote this bash shell script to use Spotlight to find files that match a file's name or its size and kind.

Usage, in Terminal:
dupecheck filename
For example, for a file called 0.pdf, output might look like this (line breaks added for a narrower display):
Possible matches based on filename:
Possible matches based on size and kind:
/Users/whoever/Desktop/Data/anthro articles/sahlins-1999.pdf
/Users/whoever/Documents/archives/another backup/
So it turns out I just downloaded a file that I already have four copies of under different names and locations.

I've set this up as a command in OnMyCommand. For this to work, it requires you to have put the shell script in a folder that's included in your $PATH. Here's the OnMyCommand command (assuming you are using OMCEdit):
dupecheck __OBJ_NAME__
Execution Mode should be set to Terminal.
  Post a comment  •  Comments (11)  
  • Currently 3.80 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)
[41,186 views]  View Printable Version
A better way to get cover art into iTunes database UNIX
A previous hint suggested a way to add your own artwork to iTunes' art database, so it's not stored inside each individual track. However, it didn't seem to work all of the time.

So I wrote some Python scripts to do this. They intercept iTunes' requests for cover art, and allow you to send your own images. They're sent back to iTunes in the same format that the iTMS sends them, so they work just as well. The script includes a basic browser-based interface for selecting images for each album. You can enter your own URLs, or search Amazon for covers.

You'll need to have Python 2.4.3 installed, and not be afraid to edit your hosts file. If you want to search Amazon, you'll also need to sign up for a free Amazon Web Services account. Download the scripts (40KB) (MacOSXHints mirror), and you'll find the instructions in the included README.txt file.

[robg adds: I haven't tested this one yet, and note that you'll have to disable your local webserver in order for this to work, as well as modify the hosts file.]
  Post a comment  •  Comments (32)  
  • Currently 3.50 / 5
  You rated: 1 / 5 (6 votes cast)
[64,718 views]  View Printable Version
Send SMS to Cingular users via Terminal UNIX
This is my first hint, and it is really a trivial idea I had. I thought it would be neat to send a text message from Terminal using curl. So here it goes:
curl -d "from=$1&min=$2&msg=$3" \
This is all on one line, of course (but with the backslash, copy and paste should work). Name the file curlsms, change the permission to allow execution (chmod a+x curlsms), and place it in a folder of your liking. To run it, navigate to its directory and the usage is:
./curlsms sender 1234567890 Message text
Replace sender with your name, 1234567890 with the recipient's phone number, and Message text with the message you'd like to send. I'm sure some of you super-creative users could integrate this into AppleScripts and do some really neat Mail rules and all that business with such a script.

Keep in mind there is a character limit on many of the text fields of Cingular's web form. This script does not make the necessary checks, and those additions would be pretty nice. Also, you can check out the form and add scheduling features and priority features as well. I am a bash shell idiot, and it would take me years to make this robust.

[robg adds: This worked; the only change I made was to add > /dev/null to the end, after the URL. I did this to route the output of the curl command into never-never land -- otherwise you'll see the URL's source code go scrolling past. With the change, you'll only see a summary of the transmission time at the end.]
  Post a comment  •  Comments (18)  
  • Currently 2.00 / 5
  You rated: 2 / 5 (5 votes cast)
[43,120 views]  View Printable Version
A ruby script to create shorter whois output UNIX
If you have ever used the whois command from Terminal, you know how many lines of legal junk comes along with the few lines of useful information you wanted. It almost always requires me to grab the mouse and scroll up a page or two to reach the vital information, and that is annoyingly wasteful. So in my quest to reduce the clutter, I wrote this ruby script to deal with the output from .com, .net, .org, and unspecified domain extensions.

I apologize in advance to any real ruby programmers out there, as this is the first script I have ever written. As far as I can tell, it works, but I imagine it is pretty inelegant, and I'm sure someone could clean it up and improve upon it. For one thing, I am not sure it deals well with all the options that you can pass to whois, but for just looking up basic details, you don't need any options.
read more (224 words)   Post a comment  •  Comments (5)  
  • Currently 3.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
[9,161 views]  View Printable Version
Rename files in bash via string handling UNIX
I periodically receive files that are somewhat cryptically named, and I like to rename them to something more understandable. I found this older hint, but it didn't work for my needs -- my renamed files contain spaces. For example, I might receive several files whose names are something like this:
And I want to rename them something like:
Total Entry #412.txt
Total Entry #413.txt
Total Entry #414.txt
After nearly tearing my hair out trying various combinations of awk and sed in my scripts, I discovered that the bash shell has its own string handling functions! This quickly allowed me create the following simple script:
for prog in *.fil; do
    mv $prog 'Total Entry #'$progno'.txt'
Voila! Note that bash starts character numbering at zero rather than one, as do awk and sed. Thus, in the example above, the substring returned by {prog:3:3} would be the numeric values in the original filenames.
  Post a comment  •  Comments (12)  
  • Currently 3.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
[28,624 views]  View Printable Version
10.4: Update to a newer bash shell UNIX
Open Terminal, and at the command prompt type bash --version. You're likely to see something like GNU bash, version 2.05b.0(1)-release (powerpc-apple-darwin8.0) -- at least if you're on Tiger, that is. Note that you'll have a powerpc version of bash, even if you're on an Intel powered Mac! Here's how I converted to a newer, Intel compiled version.

I installed a newer bash through Fink; the latest version is in the unstable tree, so you may have to modify your Fink config file. Once that's done, just type fink install bash to install. Since I wanted to be able to switch to the old version of bash, if need be, I created a symlink here:
ln -s /sw/bin/bash /usr/bin/bash
Then I updated my NetInfo profile to use /usr/bin/bash as the default shell (which in turn specifies the default shell to /usr/bin/login). I used the GUI NetInfo Manager, but you could use nicl and niutil commands if you're brave. So if something should go wonky with the 'unstable' version of bash, I can login remotely, change the symlink /usr/bin/bash from /sw/bin/bash back to the default of /bin/bash.

One could also change the Terminal preference to call the symlink, instead of using NetInfo to modify /usr/bin/login -- but the NetInfo way feels more canonical. Now type bash --version, and you should have (assuming an Intel-powered Mac) GNU bash, version 3.00.0(1)-release (i386-apple-darwin8.7.1), a whole point update, and Intel native!
  Post a comment  •  Comments (22)  
  • Currently 2.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
[17,380 views]  View Printable Version
A simple backup script for the trash can UNIX
By accident I have several times moved some important files from the Desktop to the Trash Can, and then emptied the Trash Can before discovering that the files were missing ... sigh! I decided that I needed some sort of automatic backup mechanism for the Trash Can -- in that way I would have some time to react to such mistakes.

I wrote a very simple bash script to copy files in the trash can to a backup directory:
# ; version 1.0
ditto ~/.Trash/ ~/.Trash_backup/
I invoke the script every 10 minutes via /etc/crontab, using this crontab entry: (I am the user bt):

# The periodic and atrun jobs have moved to launchd jobs
# See /System/Library/LaunchDaemons
# minute        hour    mday    month   wday    who     command
*/10            *       *       *       *       bt      /Users/bt/app-unix-scripts/

I also invoke another small script that empties the .Trash_backup directory once a week. This could be done more often, or executed manually, if you trash a large amount of data. Nothing fancy, but I think it will same me some frustration in the future. Hopefully some of you might find it useful as well.

[robg adds: Note that this script will only handle items on your boot drive. If you have multiple partitions or drives, you'll have to get fancier with the code to backup the contents of the .Trashes folder on each volume.]
  Post a comment  •  Comments (10)  
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
[7,268 views]  View Printable Version
Scripts to create an IP info summary display UNIX
I created the following scripts to mimic the ipconfig /all functionality found in the Windows NT operating system. In the unix world, all of the info is available, but not in one place which is where this script comes in handy. It concatenates all of the various pieces of IP configuration into one easy-to-read display. The bonus is all of the functions used are contained in a separate file, which can be sourced into your shell environment and used individually.

Download the scripts (4KB download), and install them wherever you like. The first script,, contains the functions that I use in the second file, Be sure to alter the second line of the file to point to the correct location of

When you run from the command line, you will receive output similar to the following:
Loopback: /
Airport: /
I split the functions out of the main script to I could use them in my bashrc file individually. The functions are as follows: get_public, get_ip, get_mask, get_gateway, get_dns, get_domain The get_ip and get_mask functions take a single argument of an interface name (lo0, en0, en1, fw0, etc.). After these are added to my shell environment, I can do things like ping $(get_gateway) or get_ip en1.

[robg adds: These scripts worked as described in my testing. Remember to make executable via chmod 755]
  Post a comment  •  Comments (22)  
  • Currently 3.17 / 5
  You rated: 2 / 5 (6 votes cast)
[17,530 views]  View Printable Version
A ruby script to clean a folder based on usage dates UNIX
I wrote this short script when I needed to clean up my Downloads folder (but it can be used on any folder). It looks at when you last accessed each file in the folder, and if it is more than a set number of days old (14 by default), it either prints out the name of the file, moves it to the trash, or deletes it.

Save the file somewhere as clean.rb, and in the Terminal (Applications > Utilities), cd to the directory (e.g., cd Desktop if it's on your Desktop), and type chmod +x clean.rb. If you want, you can edit the top of the file. There are two settings: what you want to do with the file (list, move to trash, or delete), and how long it must be since you accessed it. You can then run the file by typing ./clean.rb Downloads, for example. It will clean out or list the files according to your preference. It will only remove whole directories. Hope this is useful to everyone here!
  Post a comment  •  Comments (7)  
  • Currently 2.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
[9,223 views]  View Printable Version