Recently I've been wanting a way to pass command-line arguments to GUI apps by default, in my case a -geometry parameter to Emacs.app to make it start up in something approximating full-screen mode. It turns out there's a very easy way to do this.
As many already know, what appear as applications on OS X are in fact directories, containing the actual executable in their Contents » MacOS subdirectory. To cause this executable to be run with specific arguments, simply rename the existing executable to something else (I've used something like appname-bin) and replace it with a shell script that exec`s the renamed binary with whatever arguments you please (followed by chmod 755 or similar to make the script executable). For example, my script for Emacs.app looks like this:
The $@ at the end may or may not really be necessary, but I put it in to be on the safe side -- the OS apparently passes a parameter starting with -psn that I'm guessing is the position at which to place the app's window (remembered from the last time it was run). Emacs doesn't recognize this parameter, but other apps probably do. And as I discovered after a bit of experimentation, you do need to use an absolute path to the binary. I've only tested this on Tiger, but I'd be surprised if it didn't also work on Leopard.
When I use GeekTool, my computer won't go to sleep because my hard drive keeps getting accessed. Since I don't want to let this tool go, I have devised an alternate way to get my Mac to sleep. This remedy uses Bernhard Baehr's SleepWatcher. Now, there has been a hint about using this utility in the past, but it doesn't address a key point: your computer falling asleep when you are using it.
If you are doing a lengthy activity that doesn't involve touching the keyboard or mouse (watching a movie, for instance), your computer should stay awake. SleepWatcher doesn't know that, so in the middle of your movie, your computer falls asleep. The easy way around this is to tell SleepWatcher to sleep only when your monitor is off.
If you're running a Unix command (inside Terminal or otherwise), and you want to quickly capture the standard output in an editable buffer (for examination or snipping), just add | open -tf after the command.
The output of the command will be placed into a new TextEdit buffer, stored in the /private/tmp folder. For example, to get the output of the command-line version of System Profiler into a text file, just type (in the Terminal window):
system_profiler | open -tf
You can then edit the document, and save it (use File » Save As to pick a save location). This method saves a step over using a redirect (>) and then opening the resulting file.
In doing an mdimport -A in Terminal, I noticed a particular attribute called com_apple_ats_font_invalid. Spotlight seems to set this attribute for files in a font folder (e.g. ~/Library/Fonts) that aren't valid font files. Try this is a Terminal window to see if you have any bad fonts:
$ mdfind "com_apple_ats_font_invalid == 1"
You can see this in action if you use the -live switch on the above command. Once the mdfind starts, in another Terminal window, create a bad font:
$ echo "bad font" > ~/Library/Fonts/badfont.ttf
You'll see that the query in the first window now shows one match; remove the file you just created (rm ~/Library/Fonts/badfont.ttf), and the query count will drop to zero. Press Control-C to end the mdfind in the other window.
I'm not sure if this is new for Leopard or whether Tiger has it as well.
The stock OS X date command ships with a useful -v command that allows date calculation. For example, to determine the last day of February, you could use the following:
date -v3m -v1d
That's the third month in the first -v, and then less one day in the second -v. man date gives many examples. On the other hand, the Gnu version of date that's available from MacPorts does not support this option. Playing a bit with the --date option for Gnu's date, I came up with:
date --date="march 1 1 day ago"
This results in the same date calculation as in the stock date function. Gnu's date also includes the option of printing rfc-2822 and rfc-3339 dates. The latter can be used for applications like Google that require xls dates:
The ns means nano-seconds.
Given the different features of the two programs, it might be useful to keep both on your system, with the Gnu version of date being stored as gdate.
Google searches for Sync iDisk largely show results that say something along the lines of "just edit the iDisk version." For me, iDisk is more about backup than anything else. I don't really have the need to share Documents with other people, and the local Documents folder of my laptop is always authoritative for my data. However, it would be nice to have a synced and restorable copy of my Documents "in the cloud" in the event my laptop fails. rsync works well for this.
My first step was to log into MobileMe, click the Account link, then to click on Storage Settings. Here I dropped my mail storage from 10Gb to 2Gb and ended up with an 18Gb iDisk, perfect for backing up my critical documents. Next, I wrote up a simple shell script to handle the rsync function and to copy the data from my local Documents folder to my iDisk's Documents folder.
I've created a simple Perl script that splits a text file into 4KB parts to use within iPod Notes. Usage is pretty simple:
Copy and paste the script (macosxhints mirror) into a plain text file named makenotes.pl on your system. Remember to make the script executable (chmod 755 makenotes.pl).
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.
Open up a Terminal and go to that directory: cd ~/book
Run the script with the filename (or filenames) as arguments: ./makenotes.pl 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.
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.]
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?
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.