Archive for the 'General' Category

ftp by shell script

Monday, February 21st, 2005

I like to have a local copy of my website. With Wordpress, I write directly into my hosted site. So I have to occassionally ftp my host site to my local drive to keep them in sync. I have asked my site host to backup my sql database weekly. Then I can download it to [...]

vi and shell editing

Thursday, February 10th, 2005

I use vi for editing my httpd.conf and other config files as well as for some c programming and shell programming. One of the things I never really used well was the interaction with the shell inside of vi. If you are like me and quit vi to do some shell commands and then reopen [...]

Using you mac to share an appletalk printer

Tuesday, January 25th, 2005

This is a little easy trick for those in a Windows network environment. If you have a laserwriter that your pc can’t see (such as an appletalk protocol printer) and you have an OS X box that sees it, you can turn on Windows sharing in your preferences and share your printer. This is sometimes [...]

pushd

Monday, January 17th, 2005

In the terminal, if you find yourself needing to move back and forth between two directories and don’t want to type in the complete path name constantly, you can either set up aliases of the cd command to the directory or you can use pushd. Let’s say you are in your Sites folder in [...]

Crontab

Monday, January 10th, 2005

I have been having a lot of difficulty using Moveable Type in recent weeks. This has slowed progress on the website. I’ve made the switch to Wordpress which is a php alternative to the perl powered Moveable Type. I have found it to be a very nice editor that is very easy to install and [...]

Restart Classic

Wednesday, November 17th, 2004

Here is a shell script you can use to shutdown and restart classic. I created this to run as a cron script, so that I could shut down classic at an interval. It seemed like Classic was having memory problems if it ran too long without a reboot, so I set it up to run [...]

terminal mount command

Thursday, October 7th, 2004

I’ve been trying to understand the mount command in Unix. If anyone can shed some light on it, please do post. This is what I have figured out. You can mount an afp volume using the command mount -t afp. But you first have to establish a share point for the mount to land. So [...]

printing a directory list

Thursday, August 26th, 2004

One thing that OS X is lacking that I used all of the time in OS 9 is the print window command in the finder. There are a few ways to get around this limitation. One way is to open the window you want a print out of. Grab the icon at the top middle [...]

softwareupdate

Monday, August 16th, 2004

Apple has provided a command line utility to match the Aqua software update. This can be scripted to run and also can be run remotely using ssh.
I ran the softwareupdate command by typing in softwareupdate -i -r for install required. The discovery of this command line command is really rather nifty. Next time you need [...]

Script to mount a server

Tuesday, July 27th, 2004

In OS X you use the Go menu to Connect to a server. If you have installed the Script menu that comes with Applescript in your Applications folder you can place an applescript in there that will be a shortcut to mounting an often used server. Below is a script you can use:
tell application “Finder”
–activate
try
mount [...]

Change case

Friday, July 23rd, 2004

Here is a little perl script that you can use to lowercase text with an uppercase first letter of each word. If you put it in your BBEdit unix filters it will work on any selected text.
#! perl -w
use strict;
while () {
tr/[A-Z]/[a-z]/;
s/\b([a-z])/\u$1/g;
print $_;
}

Perl File::Copy and Apple’s ditto command

Wednesday, July 21st, 2004

You can use Perl’s File::Copy module to move files around your system. The only drawback is that if the files are macbinary and have a resource fork, that portion of the file gets lost. You can use Apples ditto command with –rsrc parameter to move files and maintain the resource.
Following is a perl subroutine I [...]

Killing a process

Tuesday, July 20th, 2004

Sometimes applications crash, or at least they don’t behave the way they should. The kill command will come in handy when you need to kill an application. I use this command to find the Distiller pid then kill it:
kill -9 $(ps -auxwww | grep Distiller | grep -v grep | awk ‘{print $2}’)
One of the [...]

Using Applescript with PERL

Sunday, July 18th, 2004

One of the great advantages of OS X is that you can control applications using Applescript. There is a command line version of calling applescript called osascript. The really cool thing is being able to use this command inside of another script such as a perl script or a shell script. One of the things [...]

Using Perl to change file names

Friday, July 16th, 2004

The previous tip showed how you can change filenames in a given directory uisng the command line. If you need to use perl to programatically change file names you can use the rename perl function. Often times I need to iterate through a directory and change names of files based on a given condition. Here [...]

Changing file names in a directory

Thursday, July 15th, 2004

Here I am changing a whole directory of file names. I am changing the extension of any file with the .tif extension to .jpg.
ls *.jpg | awk ‘{print(”mv “$1″ “$1)}’ | sed ’s/.jpg/.tif/2′ | /bin/sh
Of course you can change the sed regular expression to change it to whatever you want to change the file names [...]

Printing a man page to a postscript printer

Wednesday, July 14th, 2004

To use the terminal to print a postscript page of a man page use these commands:
groff -Tps -man /usr/share/man/man7/groff.7 | lpr -P LaserWriter_8500
I’m using an Apple Laserwriter 8500. To find the printers available to your lpr command use the command lpstat -a to list them. If there isn’t a printer available, you will need to [...]