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

Split text files for iPod Notes usage via Perl UNIX
I've created a simple Perl script that splits a text file into 4KB parts to use within iPod Notes. Usage is pretty simple:
  1. Copy and paste the script (macosxhints mirror) into a plain text file named on your system. Remember to make the script executable (chmod 755
  2. Put the script and the text you want to split into a directory. For this example, assume the directory is named book and located in your user's home folder.
  3. Open up a Terminal and go to that directory: cd ~/book
  4. Run the script with the filename (or filenames) as arguments: ./ colourofmagic.txt
When run, the script will ask you to create a title for this book -- this title is used as a directory name and as a prefix for the parts. For instance, if I use the title colour_of_magic, the script will create a directory named colour_of_magic in the current directory, and put the parts into that folder, eg colour_of_magic_1.txt, colour_of_magic_2.txt, colour_of_magic/colour_of_magic_3.txt, etc.

[robg adds: I haven't tested this one.]
  Post a comment  •  Comments (6)  
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)
[10,292 views] Email Article To a Friend View Printable Version
Use an alias to ease resumable scp transfers UNIX
If you do a lot of downloading via scp and occasionally find yourself restarting a download that failed due to a closed connection, here's an alias that can help. Add the following to your user's ~/.profile file to create a "resumable scp downloading command:
alias scpresume="rsync --partial --progress --rsh=ssh"
This command uses rsync, and sets options for resumable transfers (--partial), displaying a progress bar (--progress), and insures that the transfer will be made using secure shell (-rsh=ssh). To use the command, open a new shell after saving your modified .profile file, and then type scpresume in place of scp in your normal transfer command.

[robg adds: I added detail to the original hint submission, so I apologize if I got some of the details on the rsync options incorrect.]
  Post a comment  •  Comments (5)  
  • Currently 1.20 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)
[8,278 views] Email Article To a Friend View Printable Version
Mount CD-ROMs as a Windows user would see them UNIX
Have you ever had a CD-ROM that showed different files on different OSes? Such as a Maple12 install CD-ROM for Windows that doesn't show any files in MacOS. There are several different ways this can happen. A common way is to make a hybrid CD-ROM with multiple filesystems using the same data. Another way is with a multi-session CD-ROM. Sometimes in MacOS you need to see what the Windows user sees. The following method deals with the hybrid case.

Optical disks, and images of optical disks, have various backwards-compatible file systems. The basic file system is ISO9660, and there are several revisions of it. All revisions are generically known as ISO9660. There are also extensions to ISO9660 for specific operating systems. MacOS uses an HFS filesystem extension, Windows uses an extension known as Joliet, and Unix uses an extension known as RockRidge. MacOS understands all these and more, but prefers its native HFS. If a CD-ROM has an HFS extension, the Mac will automatically use it. The problem is that the file listing in HFS may be different than the file listing in Joliet. So how do you force MacOS to use Joliet (or anything else) instead of HFS?
read more (330 words)   Post a comment  •  Comments (12)  
  • Currently 2.33 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (6 votes cast)
[28,455 views] Email Article To a Friend View Printable Version
Back up key files via rsync and ssh UNIX
If you find online backup solutions expensive and heavy on your system, you might be pleased to hear there is a cheap, easy way to create a mirror backup your Mac (or other UNIX variant) to a secure online server using a program named rsync. And as of Mac OS X Leopard, rsync will even transfer metadata associated with your files like tags and comments.

This method does not allow you to roll back to previous dated backups like certain backup solutions do (Time Machine, for example). What it does is create a mirrored backup of your Mac on a remote server, so it's best used in conjunction with a local hard drive-based incremental backup solution. Still, if the house burns down, your files will be safe and once you've done the initial backup, rsync is very efficient at keeping your remote backup mirrored with your disk.

In this example, we're going to backup the currently logged-in user's Documents folder.
read more (582 words)   Post a comment  •  Comments (12)  
  • Currently 1.80 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)
[25,241 views] Email Article To a Friend View Printable Version
10.5: Enable https on 10.5's Apache2 web server UNIX
This short how-to explains how to get HTTPS/SSL working on Leopard, which uses apache2. First, follow the steps in this hint, but instead of following Step 5, do the following:
  • Edit /private/etc/apache2/httpd.conf, and uncomment the following line (it's line 473 in my installation):
    Include /private/etc/apache2/extra/httpd-ssl.conf
  • Edit /private/etc/apache2/extra/httpd-ssl.conf, and make sure that:
    • SSLCertificateFile points to newcert.pem
    • SSLCertificateKeyFile points to webserver.nopass.key
    • SSLCACertificateFile points to cacert.pem
    • SSLCARevocationPath points to demoCA/crl
    Be sure to include the full pathnames for each entry. Optionally, you can edit DocumentRoot to your liking. I point it to /Library/WebServer/Documents-SSL, so I have two roots, one for http and one for https.
After these steps, restart apache2. Preferably do this from the command line (sudo apachectl graceful), so that you can see if the configuration is accepted or not. After that, point your browser to https://localhost/, and marvel at https beauty.
  Post a comment  •  Comments (11)  
  • Currently 2.73 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (11 votes cast)
[31,454 views] Email Article To a Friend View Printable Version
How to access Time Machine files from Linux UNIX
Recently after switching from Mac OS X to Debian, I found I needed to restore a couple files from the Time Machine backup that I kept. The drive works just fine as an HFS+ mount, but I couldn't figure out how to retrieve anything within. When Google didn't yield the answer, I began to explore on my own.

It turns out Apple does a couple slick things with the file system to make incremental backups work, including hard linking to directories, which isn't allowed in Linux. So for anyone that needs to access their Time Machine from something other than its associated Mac, here's how you do it...

[robg adds: The following details were reproduced (with minor editing) using the author's original blog post, with his permission.]
read more (349 words)   Post a comment  •  Comments (13)  
  • Currently 3.47 / 5
  You rated: 2 / 5 (17 votes cast)
[32,370 views] Email Article To a Friend View Printable Version
10.5: A possible fix if X11 won't launch UNIX
I recently upgraded to Leopard after getting my hands on a MacBook (goodbye G3 iBook!), and was unable to use X11 from my clean install. After trying to reinstall X11 from my install disc as suggested in this hint, I still couldn't use it. After looking at both the /System » Library » LaunchAgents » org.x.X11.plist, and the console errors...
6/21/08 11:16:35 PM[122] (org.x.X11[474]) Exited with exit code: 1
6/21/08 11:16:35 PM org.x.X11[477] = /usr/X11/
6/21/08 11:16:35 PM org.x.X11[477] Unrecognized option: -launchd became pretty obvious that the -launchd flag was the problem. So I backed up /System » Library » LaunchAgents » org.x.X11.plist, and then edited it with root privileges. In the ProgramArguments key, I removed this line:
After saving the file and restarting the computer, X11 worked as expected.

[robg adds: I'm not sure why this fix was required -- my plist file contains the -launchd item, and X11 runs just fine. If anyone can shed some light on the problem, please leave a comment...]
  Post a comment  •  Comments (8)  
  • Currently 1.60 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)
[11,808 views] Email Article To a Friend View Printable Version
Create aliases to icons via a Perl script UNIX
Often I read the question "Where are all the icons on my Mac?" Here is the answer, in the form of a Perl script. Just copy and paste the below code into a new file, save it as something (findOSXicons) to a directory in your path, and make it executable (chmod 755 findOSXicons). Then use the usual techniques to start the script (i.e. calling it using the full or relative path). Here's the code:

use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
use File::Find;
use File::Basename;

# here we store the results
my $target=$ENV{'HOME'} . '/Desktop/OSX-Icons';

# you may change the extensions to use
my @extensions= qw( icns );

###### POD #################################################################{{{

=head1 NAME

findOSXicons - recursively search for all icns files in your system


[B<-target> I<targetdirectory>]
[B<-extension> I<ext>]...




B<findOSXicons> recursively traverses the startpaths (or / if none given)
and creates a directory structure containing links to each and every icon
(files ending with .icns) found.

=head1 EXAMPLE

findOSXicons -target ~/Desktop/MyIcons -extension gif -extension icns ~

=head1 OPTIONS

=over 5

=item B<-extension> I<ext>

As a default the extension I<icns> is searched. with this option you
can specify extensions to use instead. If you give this option several
times, each extension is searched

=item B<-target> I<targetdirectory>

As a default the directory OSX-Icons is created on your desktop. With this
option you can specify which output directory to create instead.

=item B<-help>

Short help

=item B<-man>

Long help


=head1 BUGS

None yet except that you get several warnings for directories you are not
allowed to acces. Use 2E<gt>/dev/null to suppress them.


findOSXicons was entirely written by Skeeve

It was inspired by several user requests in the german apple forum at


###### END: POD ############################################################}}}

##### commandline options ##################################################{{{
# defaults
&help unless GetOptions(
	"help"        => \&help,
	"man"         => \&man,
	'target=s'    => \$target,
	'extension=s' => \@extensions,
sub help { exit pod2usage( verbose => 1 ); };
sub man { exit pod2usage( verbose => 2 ); };
##### end commandline options ##############################################}}}

# append a trailing slash
$target=~ s#([^/])$#/#;
# and calculate the length
my $target_length= length($target);

# check which extensions to find
die "No extension specified\n" unless scalar @extensions;
my $extensions= join ('|',map quotemeta,@extensions);
$extensions= qr/(\.(?:$extensions))$/;

# Statistics etc.
my @removed;        # list of removed icons
my $count_old= 0;   # icons we know of
my $count_new= 0;   # new icons
my $count_oapp= 0;  # application icons we know of
my $count_napp= 0;  # new application icons

# create the target directory unless it exists
mkdir $target or die "Can't create $target: $!\n" unless -d $target;

# hash of files already linked
my %stat;
# build the hash.
find ( {
	wanted => sub {
		# get the link target
		my $lnk= readlink $File::Find::name;
		# No link target? Then skip this.
		return unless defined $lnk;
		# Does the target exist?
		if ( -e $lnk ) {
			# build the hash
			# do some statistics
			# is it an applicationicon?
			++$count_oapp if $lnk=~ m#/[^/]+\.app/#;
		else {
			# target is missing so remove the link
			unlink $File::Find::name;
			# and remeber that it was removed
			push(@removed, $lnk);
	no_chdir => 1,
}, $target);

# now find
find( {
	wanted => sub {
		# just files
		return unless -f $File::Find::name;
		# need to get the basename (no_chdir!)
		my $fname= basename $_;
		# correct extension?
		return unless $fname=~ s#$extensions##;
		my $ext= $1;
		# we don't want our target to be checked
		return if substr($File::Find::dir, 0, $target_length) eq $target;
		# check whether or not we already know of this file
		return if $stat{$File::Find::name}++;
		# create the subdir in the target dir
		my $link_dir= $target;
		# 2 possibilities
		if ( m#/([^/]+)\.app/# ) { # is it an Application's icon?
			# we put it into the Applications-subdirectory
			$link_dir.= 'Applications';
			mkdir $link_dir or die "Can't create $link_dir: $!\n" unless -d $link_dir;
			# into a directory for the application
			$link_dir.= "/$1";
		else {
			# we put it into an "alphabetical" subdirectory
			$link_dir.=  uc substr($fname,0,1);
		# create the directory
		mkdir $link_dir or die "Can't create $link_dir: $!\n" unless -d $link_dir;
		# now calculate the filename
		my $link_name= $link_dir . '/' . $fname;
		my $count= '';
		--$count while( -e "$link_name$count$ext");
		# now link;
		symlink $File::Find::name, "$link_name$count$ext";
	no_chdir => 1,
	follow => 0,
}, scalar @ARGV ? @ARGV : '/');

# Statistics
my $icon_count= $count_old + $count_new;
my $app_count= $count_oapp + $count_napp;
my $else_count= $icon_count-$app_count;
my $else_new= $count_new - $count_napp;
my $else_old= $count_old - $count_oapp;
my $miss_count= scalar @removed || 'none';
print <<REPORT;
      All icons known: $icon_count
    Application icons: $app_count
Non-application icons: $else_count

print <<REPORT if $count_new;

      New icons found: $count_new
    Application icons: $count_napp
Non-application icons: $else_new

            Old icons: $count_old
    Application icons: $count_oapp
Non-application icons: $else_old

print <<REPORT;

Icons removed since last run: $miss_count

print "$_\n" foreach (sort @removed);
By default, this script will copy a link (kind of an alias) to each and every icon in the system into a folder on the desktop in a nice hierarchy.
read more (142 words)   Post a comment  •  Comments (18)  
  • Currently 1.20 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)
[9,959 views] Email Article To a Friend View Printable Version
Discover which programs prevent disk image ejection UNIX
One of my least-favorite error messages is the one that says a volume can't be ejected because it is in use. The vague advice to "try quitting applications" often leads me on a wild goose chase -- somehow it always seems to be the last application I try that has a document on the volume open.

I finally realized that the Unix lsof command is exactly what one needs in this situation. I have known about lsof for a long time, but somehow never put two and two together. Now when the Finder tells me I can't eject the volume 'DODO,' I just run this in the Terminal:
lsof | grep DODO
The output may then look something like this:
bash       228 johndoe  cwd      DIR      14,4      4096          2 /Volumes/DODO
Word      1379 johndoe   24u     REG      14,4        81     197704 /Volumes/DODO/C/Archiver/test.txt
This shows me that Word has test.txt open, and that there is a shell whose working directory is on DODO. This makes clear exactly what I need to do to be able to eject the volume -- close the Word document and cd out of the directory on DODO.

[robg adds: This use of lsof is mentioned in the commends to a much older hint I wrote on ejecting a busy disk image using fstat. At some point in OS X's history, it seems fstat vanished (at least as an end-user program) -- I can't find it on either my 10.4 or 10.5 partition, except as a BSD system call in OS X 10.5 -- leaving the use of lsof as the preferred way of finding out what's keeping a disk image busy. Due to that change, I felt it worth running this hint as a standalone refresh of the original. If you have another method, please post it in the comments.]

[Note: This is a near-duplicate of this older hint -- thanks to hayne for pointing this out to me. However, given there's a good chain of comments here, I'm going to leave this hint up. Sorry for the duplication.]
  Post a comment  •  Comments (19)  
  • Currently 2.44 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (9 votes cast)
[25,457 views] Email Article To a Friend View Printable Version
View Doppler radar-in-motion on the desktop UNIX
This hint explains how to view an in-motion Doppler weather radar image from The Weather Channel on your desktop. A little precaution is in order, though: this will eat up quite a bit of CPU cycles (between 12% and 30% on an Intel Mac mini). I use it on a machine that does monitoring/notification, but I'd never use it on a machine I use for normal work. The "animation" is somewhat slow, but tolerable in my opinion. This hint requires use of the command line. Also, I make no guarantees that it won't break something, etc. I've only done this on Leopard, but I can't see any reason why it wouldn't work with Tiger (no Panther or earlier, because they don't have launchd).

There are two components to this: A unix script to retrieve the images from The Weather Channel or NOAA or wherever else, and a launchd agent that periodically runs the script. Here's the shell script:

if [ ! -d ~/Library/WeatherMaps ]; then
mkdir ~/Library/WeatherMaps

curl -s ~/Library/WeatherMaps/latest1.jpg;
curl -s ~/Library/WeatherMaps/latest2.jpg;
curl -s ~/Library/WeatherMaps/latest3.jpg;
curl -s ~/Library/WeatherMaps/latest4.jpg;
curl -s ~/Library/WeatherMaps/latest5.jpg;

defaults write ChangeTime 1;
killall Dock;

exit 0
Edit the script to suit your location by retrieving the image URLs from or somewhere else. I've added the commands to reset the refresh interval and restart the dock, because in my experience, this stops working after a couple hours without doing so. Drop the script in the /Library/Scripts folder. Also make sure to make it executable with this command: sudo chmod 750 /Library/Scripts/
read more (194 words)   Post a comment  •  Comments (6)  
  • Currently 1.40 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)
[14,533 views] Email Article To a Friend View Printable Version