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

Pass command line arguments to GUI apps by default UNIX
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:

#!/bin/sh
exec /Applications/Emacs.app/Contents/MacOS/emacs-bin -geometry 177x47 $@


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.
  Post a comment  •  Comments (8)  
  • Currently 3.00 / 5
  You rated: 4 / 5 (11 votes cast)
 
[19,479 views] Email Article To a Friend View Printable Version
Sleep Macs via SleepWatcher based on monitor state UNIX
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.
read more (187 words)   Post a comment  •  Comments (5)  
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)
 
[14,999 views] Email Article To a Friend View Printable Version
Capture command line output directly to a text file UNIX
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.
  Post a comment  •  Comments (19)  
  • Currently 1.83 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (6 votes cast)
 
[22,503 views] Email Article To a Friend View Printable Version
Find corrupt fonts using Spotlight in Terminal UNIX
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.
  Post a comment  •  Comments (5)  
  • Currently 1.80 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)
 
[10,786 views] Email Article To a Friend View Printable Version
Date calculations with stock and Gnu versions of 'date' UNIX
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:
date --rfc-3339='ns'
2008-07-23 18:28:00.110568000+05:30
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.
  Post a comment  •  Comments (6)  
  • Currently 1.80 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)
 
[8,052 views] Email Article To a Friend View Printable Version
Automatically sync Documents folder to iDisk UNIX
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.
read more (331 words)   Post a comment  •  Comments (13)  
  • Currently 3.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (12 votes cast)
 
[75,351 views] Email Article To a Friend View Printable Version
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 makenotes.pl on your system. Remember to make the script executable (chmod 755 makenotes.pl).
  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: ./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.

[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,086 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)
 
[7,655 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)
 
[24,254 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)
 
[23,067 views] Email Article To a Friend View Printable Version