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

Speaking in the shell UNIX
Jacob S. writes:
I wrote the following quick PERL script that uses Applescript to speak the contents of STDIN in the UNIX shell environment. See code comments for more information. Enjoy.

Some cool uses that I use this for are:
- Use in /etc/hosts.allow to alert you when a deny is triggered
- Use to speak ipfw log contents
Read the rest of the article for the (very short) script...
read more (75 words)   Post a comment  •  Comments (18)  
  • Currently 2.33 / 5
  You rated: 5 / 5 (3 votes cast)
[8,630 views]  View Printable Version
OSXvnc-wrapper woes and solution UNIX
If anyone else out there uses the OSXvnc server from [Update: is no longer a Mac-related website; the domain expired and it's now run as a porn site! Do not try to visit there!] and used the OSXvnc-wrapper solution posted there to get it to automatically run and stay up, you may be interested in this script. You will have no doubt noticed when installing Classic applications under 10.1 that when it says it must close all applications, it means OSX applications as well. This gets into an interesting loop where it kills OSXvnc, which respawns, which then gets killed, etc. As a "hack" solution, I use the following as a replacement for the OSXvnc-wrapper file:

while true
while [ `ps -aux | grep '' | grep -v 'grep' | wc -l` = 1 -a `ps -aux
| grep '' | grep -v 'grep' | wc -l` = 0 ]
sleep 1
/Applications/ `cat /etc/osxvnc-args`
sleep 10
[Editor's note: the "while" command just inside the first 'do' loop has been broken onto two lines for easier readability. Put a space after "aux" and then everything from line two onto the same line.]

What it does is check to see if Dock is running but Finder isn't (this happens when you are installing software that requires closing everything) and if so, waits for this to change. Once it runs, if it gets killed for any reason, it waits 10 seconds and starts checking again. The 10 second wait was necessary since momentarily after killing OSXvnc, both Dock and Finder are still running (finder hasn't been killed), and OSXvnc will start up again and get in the weird loop again.

I got frustrated and created this when that mysterious loop cuased me to force boot one too many times and it corrupted my FS... :( now I don't have to worry about it :)

Hope someone else finds this useful.
  Post a comment  •  Comments (7)  
  • Currently 2.33 / 5
  You rated: 5 / 5 (3 votes cast)
[6,123 views]  View Printable Version
Native (and free) fax software UNIX
efax is a small, free, command-line fax program developed under Linux. It compiles with very little tinkering under 10.1, and I have successfully sent and received faxes with it using the internal modem on my Powerbook G4. efax communicates with the modem using POSIX /dev interfaces, so I don't see why it shouldn't work with just about any modem that is supported by OS X.

For now, installing and using it is a bit (OK, very) command-line intensive, but it should be easy to wrap this up in an installer package and add a GUI interface (which I might do if I find the time - but I wouldn't be upset if someone beat me to it). Fax capability is essential for OS X, and FaxSTF X from Smith Micro is a complete disaster (I am one of the fools that sent them my money).

I have written a brief document explaining how I have used efax and ghostscript to send and receive fax documents in pdf format.

[Editor's note: In fact, a free Cocoa front-end to efax has just been released, called Cocoa eFax. It includes the efax UNIX program along with the Cocoa front end, but I have not tested the program so I can't vouch for it one way or the other. I also haven't tested FaxSTF, so I can't comment on that package, either.]
  Post a comment  •  Comments (2)  
  • Currently 2.33 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
[5,598 views]  View Printable Version
Upgrade the CVS command line tools UNIX
Type cvs -v in the terminal to see which version you have. More than likely you'll see Concurrent Versions System (CVS) 1.10 `Halibut' (client/server)

Here's how to compile version 1.11.1p1. These instructions will replace the existing Apple-supplied CVS files including the html documentation. By default, 'make' wants to install texi info files for the docs, but we're going to trash those and create html versions instead, as with Apple's distribution. Also we change the other default UNIX installation directories to use Mac OS X specific ones.

Read the rest of the article for the step-by-step instructions.
read more (121 words)   Post a comment  •  Comments (5)  
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
[6,863 views]  View Printable Version
More Terminal keybindings for the bash shell UNIX
In other *nix prompts, you can do history searches for partial commands. For instance, if you find yourself typing "telnet" repeatedly, you can type "tel and hit Page Up to search for the last command you typed that began with "tel" You can hit Page Up repeatedly to find the previous command that began the same way. You can also hit Page Down to go forward in the search if you hit Page Up too many times and missed the command you wanted.

Terminal uses Page Up and Page Down for scrolling, which is great for new users, but seriously slows power users down. Other unices use Shift-Page Up and Shift-PageDown for scrolling.

To restore command completion from history (in bash), you can use (mind the quotes!):
bind '"M-e": history-search-backward'
bind '"M-r": history-search-forward'
This binds Option-E to the reverse search (Page Up on Linux) and Option-R to a forward search (Page Down on Linux). To use this, the "Option (alt) key acts as meta key" item under Emulation in Terminal preferences must be on.

I put these commands in my .profile so that my terminal would always be configured to my tates. I'm sure there's an analogous command in tcsh.

On a side note, if you want a more powerful history search, you can hit Control-R to do a full interactive history search under bash. You hit Control-R at the prompt and type some text. Each letter you type will make the search more detailed. For example, if you want to find the last command that you executed with as a parameter, you can hit Control-R and begin typing the IP. When you type the "1" the last command with a "1" in it will be displayed. When you type "9" the last command with a "19" in it will be displayed, and so on. Hitting Control-R again tries to find another command that matches.
  Post a comment  •  Comments (1)  
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
[5,675 views]  View Printable Version
Create a command-line calculator UNIX
I love this, even though I didn't think of it myself. ;-)

Want a simple calculator that works at the Terminal prompt? As per the suggestion on this website, just put this in your ".cshrc" (or "aliases.mine" as the case may be):
alias calc 'awk "BEGIN{ print \!* }" ' 
That's it. Then run
% source .cshrc
% rehash
and you can do basic arithmetic in the Terminal application:
% calc 545+56
% calc 545-56
% calc 545*56
% calc 545/56
I like this especially because now I don't have to use the wretched Numlock key on my iBook.
  Post a comment  •  Comments (6)  
  • Currently 3.50 / 5
  You rated: 5 / 5 (2 votes cast)
[5,805 views]  View Printable Version
A replacement for the 'basename' command UNIX
I've written many unix scripts over the past years and very early on I found myself using the basename command numerous times.

As I'm always concerned about performance I looked into using the powerful shell built-in variable substition feature to reduce my use of basename.

Read the rest of the article to see what I came up with...
read more (213 words)   Post a comment  •  Comments (1)  
  • Currently 3.60 / 5
  You rated: 5 / 5 (5 votes cast)
[5,475 views]  View Printable Version
Create customized new terminal windows UNIX
Since I installed OS X, I've wanted to be able to pop up Terminal windows that have a specified title and are running a specified application. I'm about 90% there, and thought I'd share what I've written with the MacOSXhints gang.

Note that this is a Unix shell script that you'll want to copy onto your system, save with some name ('newterm'), then use chmod +x newterm or similar to ensure that it's executable.

Then you can start up a new Terminal window with the title "my terminal" and the core shell of /usr/bin/vi (for example), with:
newterm "Edit Window" "/usr/bin/vi"
Pretty cool, eh?

Read the rest of the article for the "new term" shell script.
read more (324 words)   Post a comment  •  Comments (3)  
  • Currently 3.00 / 5
  You rated: 3 / 5 (2 votes cast)
[5,688 views]  View Printable Version
Create a fixed-length bash shell prompt UNIX
This tip is stolen from instructions in the Bash Prompt HOWTO. It's not terribly innovative, and most Unix distributions (MacOS X included) come with a tolerably decent default prompt; consequently, even many very experienced Unix users don't know a lot about prompt configuration (I certainly didn't). But if you compile and install bash on MacOS X, you'll find that you are left with a very unsatisfactory default prompt. It was this problem that led me to sniff this information out.

This tip solves the dilemma of whether to use \W (current directory without path) or \w (complete path to current directory) in the prompt. On the one hand, \W doesn't contain the path (am I in /etc or /usr/local/etc?), but \w (which contains the path) can monopolize the command line. The solution: Include only the last x characters of the current working directory.

This tip will work swimmingly with bash, and maybe someone can explain how to do the same thing with tcsh in the replies (I'm a bash partisan myself, and I heartily recommend it to anyone who has to use the shell regularly). Read the rest of this article for instructions on creating a fixed-length bash shell prompt.
read more (191 words)   Post a comment  •  Comments (22)  
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
[8,144 views]  View Printable Version
Modular profile file for your shell UNIX
This tip is a shell setup technique that I have stolen from Mandrake Linux. It is only good for people that have heavilly customized their /etc/profile file, so the instructions assume a good deal of terminal knowledge. Instead of having one, monolithic profile file that is littered with different commands and environment settings, you can modularize it into a bunch of tidy, discrete items. You can do this as follows:
  1. su to root and cd to the /etc directory.

  2. Create a directory in /etc called profile.d.

  3. Use your favorite console text editor to add the following lines to the beginning of your profile file:
    for PROFILE_SCRIPT in $( ls /etc/profile.d/*.sh ); do
  4. Convert all of the commands in your profile file to individual shell scripts, and save them in /etc/profile.d (make sure they end in .sh), and delete them from /etc/profile.
Voila! Instead of having one, confusing, hard to navigate profile file, you have tidy, individual scripts. For example, my alias for ll (I use bash, so that ll is not built in) is in /etc/profile.d/, and my prompt code is in /etc/profile.d/
  Post a comment  •  Comments (2)  
  • Currently 3.67 / 5
  You rated: 5 / 5 (3 votes cast)
[8,320 views]  View Printable Version