Maintaining your Mac

Macworld has a series of articles that I found helpful on maintaining your mac.

  1. Essential Mac Maintenance: Get set up

    Perhaps the most important component to test is RAM…  Thankfully, it’s not difficult to do so, although a comprehensive test can take a while. Apple Hardware Test, included on the Mac OS X Install disc that comes with all recent Macs, has an Extended Testing option that tests your RAM.

  2. Essential Mac Maintenance: Rev Up Your Routines
  3. Five Maintenance Myths

    Myth #2: “You need to run the Unix maintenance scripts.”
    You may have heard about a collection of magical Unix maintenance scripts that OS X is supposed to run automatically. The story goes that because these scripts are scheduled to run in the middle of the night, putting your Mac to sleep or shutting it down prevents them from running—so you need to do so manually…

    An easy way to run the scripts manually is by using Mike Vande Ven Jr.’s free Maintidget 1.3, a Dashboard widget that shows you the last time each script was run and lets you manually run one or all with a single click. There are also innumerable tweaking utilities that provide similar functionality

Maven Assembly Convert Shell Scripts to use UNIX LF’s

In a previous post, Shell Scripts with Windows LF’s Fail in Latest Cygwin, I wrote about how to use Perforce to check out all files in UNIX format. However if you use Eclipse then this solution will not work because Eclipse always inserts Windows LF’s in any line you insert into a file leading to a mess with files that have both UNIX and Windows LF’s.

However if you happen to use Maven to generate / copy your shell scripts to their target directories you can take advantage of the lineEnding property in the Assembly Director. If you specify the lineEnding property to be “unix” then the outputted shell scripts will be in UNIX format. For example:

<file>
  <source>src/main/scripts/foo.sh</source>
  <outputDirectory>bin</outputDirectory>
  <lineEnding>unix</lineEnding>
</file>

Shell Scripts with Windows LF’s Fail in Latest Cygwin

I am not sure when this happened but now in Cygwin shell scripts with Windows LF’s (the infamous control M’s) fail, i.e. Cygwin fails to run them because it will complain about the ‘\r’ character.

The simple way to fix this is to change your scripts to use UNIX LF’s by calling dos2unix or “conv -U”.

If you are using Perforce on Windows and seeing this problem then you can change your client to use “share” for the LineEnd option. Since Perforce stores all its text files in UNIX format on the server then it will write them out locally on your Windows machine in UNIX format. See the Perforce Knowledge Base article, CR/LF Issues and Text Line-endings. Fortunately Windows batch scripts with UNIX LF’s still run properly.

Note that when you make this change from the “local” LineEnd option then text files you already checked out will have the Windows LF’s. You will need to do a p4 sync -f on the files you want updated to have UNIX LF’s. Also when do you a p4 diff on your opened text files it will look like the whole file has changed. Again this is because of line feed issues. Doing a dos2unix on those opened text files will solve the problem.

Color Code Outlook Messages

I am not a big fan of Outlook, I prefer Gmail, but it does have some nice features and in a corporate environment you almost never have another choice.

One of the nice features of Outlook is the ability to color code your messages.  For example you can color code the subject line to highlight messages addressed directly to you via:

Tools > Organize >  Using Colors > Messages sent only to me now appear [Blue] > Turn On

There are other filters you can turn on by clicking on “Automatic Formatting…” at the top right in the Tools > Organize > Using Colors window.

TcpView

Sometimes I will start up a server process and get an error about a port already in use. This problem always bedeviled me before as I randomly stopped processes until that port was freed up.

But today a colleague pointed out a great Microsoft tool called TcpView.

TCPView is a Windows program that will show you detailed listings of all TCP and UDP endpoints on your system, including the local and remote addresses and state of TCP connections. On Windows Server 2008, Vista, NT, 2000 and XP TCPView also reports the name of the process that owns the endpoint. TCPView provides a more informative and conveniently presented subset of the Netstat program that ships with Windows. The TCPView download includes Tcpvcon, a command-line version with the same functionality.

With TCPView I discovered and stopped the anti-virus program which was taking up one of the ports that the server needed.  This is much nicer than netstat. 🙂

Another nice tool to discover what programs are holding onto files is Process Explorer.

Update Feb 27 2014: Fortunately this still works on Windows 8.0 even though I am not sure if there has been any new development on it since 2011.

Setting up cygwin users and groups

Whenever I start my bash shell I get this annoying message.

Your group is currently “mkgroup”.  This indicates that
the /etc/group (and possibly /etc/passwd) files should be rebuilt.
See the man pages for mkpasswd and mkgroup then, for example, run
mkpasswd -l [-d] > /etc/passwd
mkgroup  -l [-d] > /etc/group
Note that the -d switch is necessary for domain users.

I tried doing what the documentation but I still kept getting that message.  I then tried one of the suggestions in the comments of this post, Cygwin users and groups « sinewalker.

$ mkpasswd -l -p /home/ -c > /etc/passwd
$ mkgroup -l -c> /etc/group

I then got this message.

Copying skeleton files.
These files are for the user to personalise
their cygwin experience.

These will never be overwritten.

`./.bashrc’ -> `/home/fkim//.bashrc’
`./.bash_profile’ -> `/home/fkim//.bash_profile’
`./.inputrc’ -> `/home/fkim//.inputrc’
Your group name is currently “mkgroup_l_d”. This indicates that not
all domain users and groups are listed in the /etc/passwd and
/etc/group files.
See the man pages for mkpasswd and mkgroup then, for example, run
mkpasswd -l -d > /etc/passwd
mkgroup  -l -d > /etc/group

This message is only displayed once (unless you recreate /etc/group)
and can be safely ignored.

I am not sure what it means but it was only displayed once.  Now that I am not seeing it anymore I’m happy. 🙂

Display Date in OS X Menu Bar

On November 23rd I ordered my first Mac laptop since my Powerbook in grad school, a white Macbook. 2.2 GHz Intel Core 2 Duo. So far I’ve been reasonably impressed but one thing I wanted is for the menu bar to display the full date. It always bothered me that you can’t do this on Windows w/o third party applications.Fortunately on Mac OS X there is somewhat of a hack to do this, How To: Display Date in OS X Menu Bar.The format I ended up choosing is:Thu Jan 10 7:07 PMwhich I think is a little cleaner than the one used in the aforementioned article.Update: As of March 19, 2008, this cute hack no longer seems to work.  Seems like one of the Mac OS X updates changed the way the date is displayed in the OS X menu bar.  Now my date looks like this:Wed 9:23 AM PDT 

Perforce and Cygwin

To get Perforce to work with Cygwin is not too difficult. One just has to make an alias for p4 like this (thanks to this excellent Perforce FAQ).

if [ -e /bin/cygpath ]; then
  alias p4='p4 -d `cygpath -w $PWD`'
fi

This alias works all the time except I think when you are in a directory you accessed via a link.

Note you don’t need to go such lengths as described in this post.