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

10.5: Fix Control-R in the Ruby interactive shell UNIX
It appears that Leopard ships with popular UNIX tools linked against a new BSD-licensed libedit library instead of more popular readline (which was the case in Tiger). This may cause few surprises if you are a hardcore shell prompt surfer.

I was especially irritated by Control-R (reverse history search) not working in irb (ruby interactive shell), which was using the new libedit library. The solution to this particular deficiency is very simple -- just configure libedit by editing a file named .editrc in your home directory. Add this line:
bind "^R" em-inc-search-prev
You can also set many different options in that file -- for more help, run man editrc.
  Post a comment  •  Comments (3)  
  • Currently 2.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (8 votes cast)
 
[9,931 views] Email Article To a Friend View Printable Version
Batch or one-time convert APE to MP3 via script UNIX
I've written a Ruby script that batch converts ape format files straight to individual ID3-tagged mp3 files for adding to your iTunes library. It uses all free software to do so. The muscle work is done by:
  • Mac ape conversion tool (ape => wav) named SuperMMX. There's no MacPorts version of this utility, so you have to hand install. SuperMMX - Google translation.
  • lame mp3 encoder using --preset extreme to convert to monolithic mp3 (available from MacPorts)
  • mp3splt to read the ape cue files and split the monolithic mp3 into tracks with ID3 tags. (also in MacPorts)
Notes:
  • mp3split uses the -f (frames) setting assuming a variable bitrate. If you tweak the lame settings, then you probably want to read the man page for mp3split and tweak that, too.
  • I've included status bars for conversion and informative output.
  • I've also included fairly robust error checking, but I knocked it out pretty quick. If you run into errors I overlooked, let me know and I'll add them.
  • Contains a verbose mode so you can see exactly what's going on behind the scenes.
  • Uses ansi term colors for easy reading (oooo ahhh colors).
  • Provides a --clean option to move the old files (ape, cue, wav, monolithic mp3) to the trash, leaving only the desired mp3 tracks.
  • --test mode if you just want to see what happens.
  • Complete usage information.
Needed ruby modules:
  • rubygems
  • optparse
  • ostruct
  • term/ansicolor
  • pathname
  • fileutils
I believe all of these packages are in Leopard by default except term-ansicolor.

I just did this pretty quickly, so I could have overlooked a thing or two. Please let me know if I did. As always, YMMV. However, I've successfully converted single ape files as well as over 80 ape files in a batch conversion with no problems.

[robg adds: A queue review site commenter noted the availability of Max, a free GUI tool to do the same thing. I'm running the script because I haven't tested either solution, so I'm not sure if one does things the other can't. Also, a script can more easily be run remotely, in case you're doing this over a network.]
  Post a comment  •  Comments (7)  
  • Currently 1.60 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)
 
[14,839 views] Email Article To a Friend View Printable Version
Use a theme with X11 graphical (GTK) programs UNIX
This hint applies if you have GTK applications installed through MacPorts. It may also work with GTK applications installed through other means, but your mileage may vary. These applications, by default, look really ugly because there's no decent gtk2 theme engine installed. But it's actually very simple to install one. In Terminal, just type:
port search gtk2
Some gtk2 packages will be displayed, but we're interested specifically in the gtk2 theme engines, such as gtk2-aurora and gtk2-clearlooks. To install one (I highly recommend one of those two), simply type:
sudo port install gtk2-aurora
You will need to enter your administrative password for sudo.

As soon as you're finished, you should also install gtk-chtheme by typing sudo port install gtk-chtheme. You may also have to enter your administrative password here. You can now proceed to select the theme you will be using in newly-launched GTK apps by typing gtk-chtheme in your terminal. A graphical application will launch that provides live previews of your selected theme. When you find one you like, just press OK.

With a theme chosen, every GTK2 application launched will look beautiful.
  Post a comment  •  Comments (2)  
  • Currently 3.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (7 votes cast)
 
[12,834 views] Email Article To a Friend View Printable Version
A shell function to make 'rm' move files to the trash UNIX
Command line users: Have you ever wished rm would put stuff in the Trash instead of just deleting it? After accidentally running rm -rf Desktop one day, I decided it was time to stop really deleting stuff when I ran rm. So I wrote is a shell function -- this means that the actual /bin/rm executable works like normal; only when you run rm from Terminal do files get moved to the Trash. This means that programs (and scripts) which delete files won't be affected.

So how do you use this? Open Terminal, and edit ~/.bash_profile (this is a script which is run every time you open a Terminal). Run nano ~/.bash_profile from the command prompt if you don't have a preferred editor. Add the following lines at the bottom of the file:
function rm () {
  local path
  for path in "$@"; do
    # ignore any arguments
    if [[ "$path" = -* ]]; then :
    else
      local dst=${path##*/}
      # append the time if necessary
      while [ -e ~/.Trash/"$dst" ]; do
        dst="$dst "$(date +%H-%M-%S)
      done
      mv "$path" ~/.Trash/"$dst"
    fi
  done
}
Save the file and exit. (Hit Control-X in nano; it'll ask if you want to save, press Y and hit Enter to accept the default filename.)
read more (385 words)   Post a comment  •  Comments (28)  
  • Currently 2.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (8 votes cast)
 
[27,518 views] Email Article To a Friend View Printable Version
A script to download and convert multiple YouTube videos UNIX
There are many solutions on the web on how to download YouTube videos using bash scripts, e.g. see this one as an example. However, using scripts described in the above link may be a little uncomfortable if you wish to get lots of YouTube clips. So I've modified those scripts a little bit so that the URLs are put into a single file with this structure:
url1
name1
url2
name2
...
urlN
nameN
where urlN and nameN are Nth clip's URL and desired local filename for the saved movie file.
read more (253 words)   Post a comment  •  Comments (10)  
  • Currently 2.57 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (7 votes cast)
 
[29,585 views] Email Article To a Friend View Printable Version
A command line crossword solving assistant UNIX
I'd been looking for a simple way to leverage OS X's built-in Unix dictionary to solve crossword clues, and came up with this little gem of a script:
#!/bin/bash

echo -n "Please enter a word pattern to search for (use a . for unknowns): "
read text

echo `grep -w $text /usr/share/dict/words`
Just paste into your text editor of choice, save somewhere, make sure to chmod +x the file and boom, you have yourself a very simple crossword solver! Granted it isn't perfect, but it's a good start.

[robg adds: Just to clarify, the Unix dictionary isn't the same as the built-in dictionary you access through the Dictionary program. While the Unix words file does hold a large number of words, it doesn't have everything you'll find in Dictionary app.]
  Post a comment  •  Comments (20)  
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)
 
[10,266 views] Email Article To a Friend View Printable Version
Sort files into date-labeled subfolders using Perl UNIX
When I installed Leopard, I installed it to an empty partition using a clean install. I then manually migrate my older documents and settings over time -- it's not that I don't trust the Migration Assistant (well, I don't trust it completely, but that's another story), but that I look on each major OS X upgrade as the chance to clean house. So this weekend, after a slow migration, I decided it was finally time to zero out the old 10.4 partition ... but I had a slight problem.

I archive my iChats, and have done so for many years. In those archives, there's a ton of knowledge that I prefer to keep rather than lose, so I wanted to move the archived chats into my current iChats folder on the 10.5 disk. In 10.4, all iChat archives were stored at the top level of your user's Documents » iChats folder. In 10.5, however, archived chats are now sorted into subfolders based on the date of the chat. I wanted to move my huge archive to the 10.5 partition, but I didn't want to clutter the archives folder with thousands of files at the top level -- I wanted them sorted by date, as in 10.5.

I was pretty sure that Perl could make short work of this problem ... if only I knew Perl. Thankfully, I know someone who knows Perl; you might even say he wrote the book on it. Randal Schwartz (aka merlyn here on macosxhints.com) came to my rescue with a nifty bit of code he cobbled together while waiting for a flight.
read more (302 words)   Post a comment  •  Comments (5)  
  • Currently 1.75 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)
 
[12,356 views] Email Article To a Friend View Printable Version
Add an Insert key in Terminal and X11's xterm UNIX
I need an insert key to work with my company's custom software, not to mention all the little annoying little Unix programs that expect a INS key. With X11 apps, its easy to use xmodmap f12 to temporarily emulate an insert key. Just type the following in xterm:
xmodmap -e "keycode 119 = Insert"
Now the F12 key acts like insert in all X11 apps, as long as you run them from the terminal. The best part is that keyboard settings go back to normal as soon as you close the Terminal, so you don't have to worry about changing it back. That's all well and good, but I prefer to use the Mac's Terminal.app when possible. Fortunately it's pretty easy to emulate an INS key there, too. In Terminal.app's Preferences, go to Settings and select Keyboard. Find the Key you want to replace -- in my case, F12 -- and change the default Action value to:
\033[2~
Note that the \033 is the Escape key, not those literal characters. I haven't been able to find a way to easily revert the setting, but I don't tend to need the F12 key in the Terminal, so I just leave it.

[robg adds: As submitted, the hint contained the actual key sequence and instructions to copy and paste it into Terminal. However, between Geeklog submission and publication, something munged the string, so I had to remove it. Theoretically, you should be able to type Escape followed by [2~ and make this work. However, I created the sequence by editing the existing definition for F12 (double-click it), as it ends in 24~. In the edit box, there's a Delete One Character button, so I clicked the mouse to the right of the 4, then clicked the button to delete one character. However, I'm unsure about testing the functionality of this keystroke, as I rarely use X11 apps.]
  Post a comment  •  Comments (2)  
  • Currently 2.71 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (7 votes cast)
 
[21,726 views] Email Article To a Friend View Printable Version
Download files from web servers via ftp program UNIX
The command line BSD ftp utility that ships with OS X can be used to download files via HTTP as well as FTP. For example, in Terminal, you would do this to download a DMG file from some site:
$ cd ~/Downloads
$ ftp http://www.some_site.net/file.dmg
You will see the file automatically begin downloading into your current directory, which you set to your Downloads folder with the first command. Now you probably won't need to install the GNU wget utility.

[robg adds: Note that OS X also ships with curl installed, which can do the same thing and much more (man ftp and man curl for more on both these apps, of course.) To grab the same file with curl, you'd use curl -O file.dmg.]
  Post a comment  •  Comments (6)  
  • Currently 2.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)
 
[9,757 views] Email Article To a Friend View Printable Version
Clear msftres and other GPT 'flags' set by GNU parted UNIX
This hint most likely only applies to people who have installed or used Linux on an Intel-based Mac. If this is not you, you may want to stop reading now.

Anyway, if you have tried to edit a GPT partition map using GNU parted, or a utility that uses libparted, and if you're not very good about following directions (like me), you may have accidentally set some of the partition "flags" that it exposes, such as msftres or boot. I put the term "flags" in quotes because it appears that parted actually changes the partition's type in the GPT from whatever it was before to -- in the case of msftres -- a "Microsoft Reserved" partition (GUID E3C9E316-0B5C-4DB8-817D-F92DF00215AE). These can have some unintended consequences -- as I found out, setting boot on any partition besides the EFI reserved one at the beginning of the disk will make any OS X installations on that disk unbootable.

Fortunately, boot can be easily unset the same way you set it (using parted). But, when you do so, at least using the version of parted that comes with Ubuntu Gutsy, the msftres flag is set, and parted won't let you unset it no matter how many times you try. The main problem this caused for me was that the partitions marked as msftres would no longer be mounted automatically by OS X, so they didn't show up in the Finder, and they were grayed out in Disk Utility. diskutil list indeed showed their type as "Microsoft Reserved Data" or something to that effect. (I don't remember exactly, and I didn't feel like changing the type back just to do testing for this hint.)

But -- and here's the hint -- it turns out that Disk Utility will still let you (try to) mount the partition, even though it's grayed out! Just select the partition and click Mount in the toolbar. If the filesystem is one that OS X recognizes (including FAT32 or NTFS), the volume will mount successfully and you can use it in OS X once again. What's more, as you can confirm using gpt or another utility, Disk Utility rewrites the partition map for you, back to the way it should be. (Although I don't know whether it does this on mount or when you later unmount the partition(s) in question, e.g. the next time you shut down OS X). At that point, everything is good as new.

I hope this helps someone out there; much anxious Googling didn't reveal anyone else who had figured out how to unset msftres.
  Post a comment  •  Comments (13)  
  • Currently 2.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)
 
[34,157 views] Email Article To a Friend View Printable Version