10.5: A few tips on using X11 in 10.5
In Leopard, X11 is now launched on demand by launchd, which means it's now started automatically any time you start an X application. This is a very good thing, but it means that you may have to fix your configuration files. In particular, launchd is now in charge of setting the DISPLAY variable, so if you manually set it (say, in ~/.bashrc or ~/.MacOSX/environment.plist), your X apps will be unable to find the server. To make things work properly, just don't touch the DISPLAY variable at all in your init scripts.Also, this means you shouldn't keep X11.app in your Dock. If you launch it by clicking on its Dock icon, you'll end up with another X11 icon in the dock. (For reference, here's a very informative post on the subject from Apple's x1...
published on Wednesday, the 7. November 2007, macosxhints
Use Growl to monitor long-running shell commands
While waiting for long-running shell commands to finish, I often switch to Mail or Safari. Here's how I made Bash notify me via Growl whenever one of those commands finishes. It's a combination of a clever bash script by glyf and Growl's growlnotify shell script. Install Growl, including the growlnotify shell script (found in the Extras directory). Next, download preexec.bash.txt [hints mirror] and save it under ~/.preexec.bash, as an invisible file in your home directory (in case you choose a different filename or location, make sure to adjust it in the following script).Then add the following code to your ~/.bashrc:
published on Thursday, the 11. October 2007, macosxhints
A simple way to open files in X11 applications
Here is the easiest way, to my knowledge, to associate file extensions with X11 applications: just use the open source X11 Extension program. On the disk image, you'll find a new ExtManager System Preferences panel. Install it, then open it in System Preferences. The next step is to define file extensions and commands associated with them (e.g. /sw/bin/gv for EPS files).There might be a small problem if you're using applications from outside standard PATHs (e.g. from Fink); in that case, you have to pass the PATH environmental variable to the X11 window manager. For some reason, the Apple xterm fails to assign the proper values to PATH if they're included in the .xinitrc file, and it doesn't read the .bash_profile file either. As a workoround, I suggest creating a .bashrc file with a single line (assuming the paths are already defined in the .bash_profile file, which is a...
published on Wednesday, the 19. September 2007, macosxhints
A perl script to find large directories in a given folder
Here's a little perl script that can be used to find the top ten largest directories from the argument directories. To use it, save it as dirsize in your user's .bin folder (and make it executable with chmod a+x dirsize), modify your .bashrc to add ~/bin to your path, then run something like this in Terminal: dirsize ~/*. Here's the code:#!/usr/bin/perluse strict;die "usage: $0 <directories>\n" unless @ARGV;@ARGV = map { "'$_'" } @ARGV;my @results = `du -hs @ARGV`;@results = sort human_sort @results;@results = @results[0..9];print @results;#---------------------------------------------------------------------------sub human_sort { my ($size_a) = $a =~ /^(\S+)/; my ($size_b) = $b =~ /^(\S+)/; $size_a = $1 * 1024 if $size_a =~ /^(.*)k$/; $size...
published on Friday, the 14. September 2007, macosxhints
View WordPerfect for Windows files in Terminal
I have hundreds of WordPerfect for Windows files with contents that I don't need to edit, but often view. They can be opened with NeoOffice or AbiWord, but both of these are fairly slow when I just want to quickly view a file's contents. So I created a contextual menu item which (in the blink of an eye) opens a Terminal window containing the text of the file. Here's what you need to make it work: OnMyCommand wpd2text. Note that they used to have Mac binaries here, but it looks like you will need to compile it yourself now (you'll need the Developer Tools to do that). Add this to your .bashrc file: function settitle() { echo -ne "\e]2;$@\a\e]1;$@\a"; } (taken from this hint). Once that's all done, add ...
published on Monday, the 28. August 2006, macosxhints
Yet another simple command line Calculator
Add the following to your .bashrc for a quick calculator:calc () { echo "$@" | bc -l}Now at the prompt you may try something like...$ calc "2 * 3F"...and instantly receive the result -- no need for some GUI tool.[robg adds: There are two other command line calculator hints here. This one worked for me, at least with the commands added to my .bash_profile file.]
published on Tuesday, the 8. August 2006, macosxhints
Yet another simple command line Calculator
Add the following to your .bashrc for a quick calculator:calc () { echo "$@" | bc -l}Now at the prompt you may try something like...$ calc "2 * 3F"...and instantly receive the result -- no need for some GUI tool.[robg adds: There are two other command line calculator hints here. This one worked for me, at least with the commands added to my .bash_profile file.]
published on Tuesday, the 8. August 2006, macosxhints
Prevent Terminal from opening without approval
A few days ago on Heise Germany, I found a solution for the ability to run Terminal scripts via a disguised downloaded file. Just insert the code from that forum post into your user's .bashrc file, and Terminal will ask befor...
published on Tuesday, the 28. February 2006, macosxhints