Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,000 hints and counting!

Record CPU usage for a given process over time UNIX
For an upcoming project involving virtualization applications, I wanted an easy way to record the CPU usage for a given program over time.

I'm aware of the Instruments program included in the Xcode Developer Tools, but I was looking for something simple, that I could run without a lot of overhead, and that would just record data for further analysis in Excel.

After a bit of digging with Google, I didn't find anything that quite worked (a friend tells me that mrtg and Cacti should handle this; I haven't tried them yet), so I created a relatively simple bash script to get the job done - special thanks to Keith Bradnam for assistance in making it more interactive.

The program reports on a chosen program (process ID, actually) at a specified interval, then saves a few items (timestamp, process ID, CPU usage, and command name) to a text file, in this format:
20:20:39 29916  15.7 firefox-bin
20:20:41 29916   4.0 firefox-bin
20:20:43 29916  48.6 firefox-bin
The program does not create pretty graphs, or do any sort of analysis -- that part is up to you! However, with the data, you can do some interesting things. For instance, the graph above (click it for a much larger version) shows Firefox's CPU usage while browsing and playing a few Flash games on my MacBook Pro for ten minutes or so.

Read on for the details...

read more (256 words)   Post a comment  •  Comments (12)  
  • Currently 4.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (7 votes cast)
 
[3,236 views] Email Article To a Friend View Printable Version
Download all Apple open source OS X files at once UNIX
While it is well known that Mac OS X contains open source code, how to access and download that source code is perhaps less well known. Apple publishes all its open source code on their Apple Open Source site. However, this site makes you download each program individually, without an obvious option to download an entire OS X release at once (i.e., all public sources for 10.6.1).

So I wrote the following bash script to automate the download procedure. It downloads the individual tarballs for each program, expands them locally, and then rolls everything up into one big tarball for local storage. Some caveats are that this script does not build the code, and that you are bound by a variety of licenses which are not included here (because no Apple code is included here).
#!/usr/bin/env bash
# --- applesource.bash --- downloads source code for an entire Apple release

# Take input from command-line (use "10.5.8", "10.6.1", etc.)
  version="mac-os-x-`echo $* | tr -d "."`"

# URL:
  homepage="http://www.opensource.apple.com"
  URL="${homepage}/release/${version}/"

# Announce beginning, and prepare a directory for the untarred sources
  echo "Preparing to download..."
  sources="./${version}-sources"
  mkdir -p ${sources}
  
# Process the webpage for the locations of the tarballs themselves
  curl --silent ${URL} | sed -n 's/<a href="\(.*.tar.gz\)">/\1/p' | \
    while read line; do
    
      # Find and announce the name of the next tarball to be downloaded
        tarball=".${line}"
        echo -e "\nDownloading `basename ${tarball}`..."

      # Download the tarball and keep Apple's original directory structure intact
        curl --create-dirs --output ${tarball} "${homepage}${line}"

      # Untar into the "sources" directory (see line 13)
        tar xfz "${tarball}" -C ${sources}

    done

# Compress all sourcefiles into a single tarball for posterity
  echo "Creating ${version}.tar.gz from all sources..."
  tar cfvz "${version}.tar.gz" ${sources}

# Explicitly show that everything finished.
  echo "Done."

# I like for my Mac to talk to me, although sometimes this can be creepy.
  say "The source of ${version} is now ready."
Save the above somewhere on your path, make it executable (chmod a+x scriptname), and then run it with the version number you'd like to download: getsource 10.6.1, for instance. I am a bit shy about releasing my scripts, so please be gentle!

[robg adds: I tested this and it worked as described.]
  Post a comment  •  Comments (2)  
  • Currently 4.20 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)
 
[2,685 views] Email Article To a Friend View Printable Version
Highlight the current date on a GeekTool 'cal' geeklet Desktop
I've noticed that a number of people (in addition to myself) like to display the output of the cal utility in a GeekLog geeklet (see this older hint, for example).

Unfortunately, there's no easy way to highlight the current date in the output, and the only workaround I've seen mentioned is to run the output through awk to put braces around the current day. That's a bit ugly for my taste, so I endeavored to find a way to highlight the current day with another color.

My solution uses perl, and instead of putting braces around the current date, it replaces everything but the current date with a space, and strips out the header lines (the month and the weekdays):

cal | perl -wne 'BEGIN{chomp($d = `date "+%e"`)} if (/^ *\d/) {s/\b$d\b/"#" x length($d)/e; s/\d/ /g; s/#+/$d/g; print}'

To use this, you make two calendar Geeklets in GeekTool: one which displays the normal output of cal, and one which displays the output of the above command with the text in a different color (I chose yellow), both in a monospace font, of course. Finally, you position the single-day calendar precisely over the full-month calendar, so that the highlighted day sits exactly over the current day.

As the day changes, it should always align with the full-month calendar behind it, making it appear as though the current day is highlighted. The end result is seen in the image at right.

There's one caveat: GeekTool does weird things to the spaces if you center the single-day calendar output, so you'll need to make sure that at least that Geeklet is left-aligned. The full-month calendar can still be center-aligned, though.
  Post a comment  •  Comments (7)  
  • Currently 4.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[2,334 views] Email Article To a Friend View Printable Version
Make Entourage work well with Time Machine - revisited Apps
One problem for people like me who are still using Microsoft Entourage as their email client under OS X 10.5/10.6 has been its huge monolithic database file. Time Machine will try to back up the database file every time it is modified, even though only a few megabytes out of several gigabytes of the file have been changed. This can quickly fill up your backup storage, and if Time Machine is working over a network, each backup can take a long time.

This hint, which is essentially a non-geek version of this previous hint, will enable Time Machine to incrementally back up the Entourage database file. No command line operations or Unix scripting needed here; all will be done in the GUI.
read more (308 words)   Post a comment  •  Comments (20)  
  • Currently 4.73 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (11 votes cast)
 
[3,809 views] Email Article To a Friend View Printable Version
Preserve timestamps when copying from FAT to HFS+ System
Imagine you have made a world tour in August 2009 (summer time!) and you have used your digital photo camera to create pictures, videos and voice recordings.

In this guide I will not refer to these items by their specific characteristics (photo, video, audio), but simply regard all of them as "files." Secondly, we assume that the files are saved on a storage medium, which is very likely formatted as FAT (as specified in the DCIM standard for digital cameras).

You have created three files in America/Los Angeles (UTC-0700), three files in your hometown Europe/Vienna (UTC+0200) and three files in Asia/Bangkok (UTC+0700), and at the end of the summer, you return to your hometown Europe/Vienna.

This guide shows you how to correctly bring your files' timestamps from a local time zone-based file system (such as your external flash drive, formatted as FAT32) to a file system using coordinated universal time (UTC) (such as your internal hard disk, formatted as HFS+) using the Finder on MacOS X.

read more (986 words)   Post a comment  •  Comments (5)  
  • Currently 3.63 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (8 votes cast)
 
[1,952 views] Email Article To a Friend View Printable Version
10.6: Format text via a Service and emacs System 10.6
Snow Leopard only hintOne very nice emacs feature is its text formatting functions. Combining the Snow Leopard Automator Services with emacs' scripting capabilities, one can easily, from any application, refill a paragraph to lines of 70 characters and indent list items:
  1. Open Automator, create a new Service.
  2. Set it up so the Service receives selected text from any application and replaces selected text.
  3. Add a new Run Shell Script action.
  4. Type in the script below, and save the Service.
Script:
tmp=/tmp/emacsmail`date "+%s"`.txt
 
cat /dev/stdin | tr '\r' '\n' > $tmp
 
/usr/bin/emacs -batch $tmp \
  -eval "(prefer-coding-system 'utf-8)" \
  -eval '(setq paragraph-start "\\-\\|$" paragraph-separate "$")' \
  -eval '(fill-region (point-min) (point-max) nil)' \
  -eval '(untabify (point-min) (point-max))' \
  -f save-buffer
 
cat $tmp
read more (128 words)   Post a comment  •  Comments (3)  
  • Currently 2.67 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[1,806 views] Email Article To a Friend View Printable Version
Make Safari open links from applications in the current space Apps
Safari is my default browser, and I have its preferences set to open links from applications in a new tab in the current window. In addition, I use Spaces to segregate my tasks, and I have the 'When switching to an application, switch to a Space with open windows for the application' Spaces' preference unselected.

It is often the case that I have a Safari window open in Space 1 (say), but I've switched to Space 2 to work on another task. I then need to open a URL from an application other than Safari while working on the Space 2 task. If Safari doesn't already have a window open in Space 2, but does have a window in Space 1, Safari opens the URL in a new tab in the window in Space 1. I would rather Safari open a new window in the current Space to handle the URL.

This is doable, but requires a little magic.

read more (361 words)   Post a comment  •  Comments (7)  
  • Currently 5.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[2,567 views] Email Article To a Friend View Printable Version
Return to previous message in conversation in Mail Apps
If you organize your messages by conversation (View » Organize by Thread), you can press Option-Space to go to the previous (older) message in the currently-selected conversation (while Space goes to the next (newer) message).

[robg adds: This is different than using Shift-Space (and Space) to navigate the message list -- Option-Space will only work within the current conversation, while Shift-Space goes through the entire message list.]
  Post a comment  •  Comments (6)  
  • Currently 3.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[1,615 views] Email Article To a Friend View Printable Version
10.6: Use Quick Look to see partially downloaded (*.part) files System 10.6
Snow Leopard only hintIn Snow Leopard, *.part files can be partially viewed by Quick Look while they are still downloading. For images, you'll see the image load line by line; for movies, you can see the opening frames, etc.

  Post a comment  •  Comments (0)  
  • Currently 5.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (7 votes cast)
 
[1,596 views] Email Article To a Friend View Printable Version
10.6: Avoid issues with Cisco VPN and certificate-based login Apps
Snow Leopard only hintIf you are using the Cisco VPN Client in Snow Leopard, and you have to use a certificate to log in, make sure you store the certificate in the .pkcs12 format before you try to import it into the Cisco store.

The Cisco store does not recognize the normal Windows format of certificates (i.e. DanID). I find this out by coincidence, and now, everything works like a charm.
  Post a comment  •  Comments (2)  
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[1,995 views] Email Article To a Friend View Printable Version