Archive for the ‘Macintosh’ Category

How to Tell Thunderbird to Really Delete Messages From Your IMAP Server


Monday, June 8th, 2009

This quick tip is for Mozilla Thunderbird users who use Thunderbird with an IMAP account, but also use another mail user application (MUA) such as Outlook or webmail. If you’re in a similar situation, you might notice that when you delete messages in Thunderbird, they remain visible in your other MUA, until you exit Thunderbird. This can be especially impractical, for example, when you left Thunderbird running at the office and go to check your webmail from home. All of the spam you deleted in Thunderbird is still sitting there.

Fortunately, there’s an extremely simple solution to this problem. In Thunderbird:

Preferences -> Advanced -> Config Editor…

Search for “expunge”, and enable the “mail.imap.expunge_after_delete” option by double-clicking it. You need to restart Thunderbird after applying this setting.

Here are the before and after shots:

Expunge - Before and After

This setting tells Thunderbird to automatically “expunge” (IMAP terminology for “permanently delete”) any messages that have been deleted within Thunderbird. Otherwise, it just marks the message with a “delete” flag that many other mail clients ignore by default.

The “expunge_after_delete” option should be safe to use; your Trash folder will still work normally. This setting only controls the communication with the email server.

Evaluate Your Display Configuration


Thursday, January 1st, 2009

Happy New Year, everyone.

Michelle V. Rafter has written an interesting article about multiple monitors. She contacted me in December to obtain permission to publish some of my comments. Her article contains a healthy dose of anecdotal support for multiple displays, as well as some links to multiple display how-to information.

Rafter makes the claim that “Business people who’ve made the switch say using two monitors — or even more — make them more productive. And they swear they’d never go back.”

To me, Rafter’s article serves as a good reminder to really evaluate your computer display(s) in the new year, to determine whether you really have the optimal display configuration for the type of work you do. (Do you?)

Function return value versus exit code


Wednesday, November 19th, 2008

In projects I’ve worked on in the past few years, I am noticing what seems like an increased confusion toward program exit codes and function return values. In particular, I’ve found that some programmers seem to feel these two separate things should be related somehow. They’re not related, nor should they be. In a nutshell: programs exit with 0 for success; boolean functions return 1 for success. In this article, I’ll discuss some of the motivation behind these separate and seemingly counter-intuitive conventions.

Function Return Values

As far as most computers (and their programming languages) are concerned, the value 0 is almost universally equivalent to “false”, while 1 (or, any positive integer) typically equates to “true”. This is basic Boolean logic. Here is a typical construct in C:

int is_even(int num) {
        return (num & 1);
}

/* Later... */
if (is_even(some_number))
        printf("some_number is even\n");

Most functional languages have similar constructs. Even in languages that support exceptions or other error mechanisms, the tried and true Boolean is still appropriate in a large number of situations–enough for many languages to define a dedicated “bool” or “Boolean” type. In the above code, for example, it would not be at all appropriate to throw an exception if the number is odd. All of this is well-known and seldom questioned.

Program Exit Codes

Program exit codes, however, are a completely different concept. Unlike return values, which occur within a program, exit codes are essentially part of the program’s output. While the semantics differ slightly between operating systems, the basic theory is the same:

  • An exit code of 0 means success
  • A non-zero exit code means some kind of failure

Hence, to preserve the 0 = false thinking, it may be easier to semantically think of exit codes as “error codes”. 0 means, “no, there was no error”. DOS actually got this right; it calls its exit status variable %errorlevel%.

Unix/Linux/Mac

Under Unix-like operating systems, exit codes are pretty well-defined:

0 Success
1..126 Failure (the program itself will decide what the numbers mean)
127 Command not found
128..254 The program did not exit normally. (E.g., it crashed, or received a signal)
255 Invalid exit code

From a Bourne shell, the variable $? holds the exit code of the last command run in that shell. (For csh, use $status). For example, if I run:

$ grep root /etc/passwd
root:x:0:0:root:/root:/bin/bash
$ echo $?
0

As you can see, grep actually found a match, which means it was successful. So, when I check the exit status ($?), the result was 0.

If a command isn’t successful, it goes like this:

$ grep no-such-animal /etc/passwd
$ echo $?
1

If I attempt to run a command which doesn’t exist:

$ grepadoodle foo
-bash: grepadoodle: command not found
$ echo $?
127

Finally, let’s say I ran the following command, and then was forced to kill it from another shell:

$ grep "Jimmy Hoffa" /dev/random
# This command will run forever if I let it, so at this point I go to another shell and kill it
Terminated
$ echo $?
143

Why 143? The TERM signal (the default signal sent with the kill(1) command) has a value of 15. 128 + 15 = 143.

Why This Matters

Unix shells have built-in Boolean operators like && (logical and) and || (logical or) that can be used to compare against the exit status of a command. These operators assume 0 = success (true) and !0 = failure (false). This allows us to write constructs like the following (Bourne shell):

$ grep fluffy /etc/passwd && echo "Your user list may contain a poodle."

$ [ -f somefile.txt ] || cp somefile.txt.defaults somefile.txt

If a program’s exit code does not follow the 0 = success rule, the logic rapidly gets confusing.

Windows/DOS

Here the situation is a little bit different, but not by much. In DOS/Windows batch files (or a command shell) the variable %errorlevel% contains the exit code of the last command executed, similar to Bourne shell’s $?. The semantics are similar:

0 Success
1..255 Error (again, meaning depends on the individual program)

Examples:

C:\> echo "Hello"
Hello

C:\> echo %errorlevel%
0

C:\> type nonexistent-file.txt
The system cannot find the file specified.

C:\> echo %errorlevel%
1

Where People Tend to Get Mixed Up

While virtually every built-in or well-known 3rd party command follows the above exit code rules, I have seen my share of proprietary applications that flip this logic around for no good reason. When speaking with the developers, I almost universally hear “but in [insert programming language here], 0 is false and 1 is true”. If you find yourself falling into this trap, just remember that the exit code of your program is part of its output, not part of its logic. You wouldn’t think of dumping a raw struct or object to the user’s terminal, would you? Instead, you format the output in a way that makes sense. Exit codes are no different.

Occasionally, I even see people flipping the boolean logic within programs for no good reason (and often without documentation), which leads to all sorts of confusing and error-prone constructs like this:

if (did_it_work())
        fprintf(STDERR, "Error\n");  /* Are you sure? */

There are a few reasonable exceptions to this rule, such as strcmp(3), which returns 0 if the strings are equal, < 0 if s1 is less than s2, and >0 if s1 is greater than s2. However, strcmp(3), fork(2) et al., are not boolean functions; they return a range of values instead of a simple truth value.

Summary

When in doubt, remember the following:

  1. Program exit codes are not function return values
  2. Boolean functions return 1 for true, 0 for false
  3. Programs exit with 0 on success, non-zero on failure

Keep it clean!

Put Mac OS X Dashboard Widgets on your desktop


Sunday, July 6th, 2008

Picture 3.png

The Mac OS X Dashboard is nice enough to completely disappear when you tell it to go away. However, in some cases, you might want one or two of the widgets to remain visible all the time, even if the Dashboard is not active. Here’s how to hack your Dashboard to do just that, in OS X Tiger or Leopard:

If F12 doesn’t bring up the dashboard: Some newer Mac keyboards have multiple functions assigned to the F12 key. If F12 turns up your system volume instead of bringing up the dashboard, you probably need to press Fn + F12 when the video prompts you to press F12.

Quick Reference

For a quick reference (or for you experts out there), here is a summary of the steps:

  1. Open Terminal (Macintosh HD -> Applications -> Utilities -> Terminal)
  2. Type the following commands:

    defaults write com.apple.dashboard devmode YES
    killall Dock

  3. Press F12 (or Fn + F12) to bring up the Dashboard
  4. Click and hold the left mouse button on the desired widget
  5. Press F12 (or Fn + F12) again
  6. The widget is now on the desktop

To put the widget back in the Dashboard, simply repeat steps 4 and 5.

If you found this helpful, I would really appreciate it if you would give the video a 5-star rating on YouTube.

Tags: , , , , , ,