Archive

Archive for November, 2010

Make your Mac more like an iPhone: How to reduce distractions and improve focus

November 11, 2010 3 comments

While our desktop computers excel at multitasking due to their multiple cores, the human mind fares much worse.  There have been multiple studies showing that multitasking can impair productivity.  Often the reasoning is that the brain requires time to adjust between different tasks, due to the switch in context.  An analogy for this would be driving on a highway.  You’re going to cover a lot more ground in the same amount of time if you can keep a constant speed (focusing on one task) rather than having to constantly take exits and switch to new roads (tasks).  While those who multitask frequently might think that switching tasks bears no greater cost to them than switching lanes on the highway, the studies suggest that the cost in focus and time in switching to the new task is more akin to having to take that offramp, find a new highway, and then get back up to speed.

But enough about metaphors and science.  I am not a cognitive scientist so I’ll leave that up to the people who do it best.  I can only speak for myself, and I find that it’s supremely tempting to pick away at pieces of problems rather than to focus on one thing and make significant progress in that regard.  I also know that I am objectively less productive if I constantly am switching tasks.

It is for that reason that I’ve assembled a set of tools that allow me to have a stronger single-minded focus while working on a computer.  While there are systems such as Getting Things Done and the Pomodoro Technique which address the human aspect, I’m going to be focusing more on technological solutions with respect to working on an Apple computer.  While many criticize the iPhone and iPad for their limited multitasking support, I think having full-screen applications and focusing on one thing at a time is very beneficial.  With that thought in mind, the rest of this post will show various ways to make the Mac less suitable for multitasking and closer to the iPhone/iPad model of computing.

Hide the dock

Why

Gain more desktop real estate.  Eliminate the visual clutter at bottom of the screen.

How:

Right click on a portion of the dock which does not have an icon, e.g. on the portion where the dock can be resized.

Reduce use of tabbed browsing

Why

I love the ability to open multiple webpages in a single browser.  It can be supremely useful when you are researching and need to have multiple pages open to reference.  Unfortunately it can also lead to shallow reading and a mild form of A.D.D. wherein the user (i.e. me) keeps opening new links with the intention of reading them later.  There is seemingly no cost to opening a link in a new tab, but it does exert a cost – it makes it harder to find the tabs that are actually relevant, and it also uses more system memory.

How

There is a discussion on the Firefox feature request group to limit the number of tabs that one can open at a time, for reasons similar to what I have presented above.  The best solution given is to install a TabCounter extension in FireFox which shows how many tabs you have open.  It still requires you to monitor the number and prune the number of tabs when things get too bogged down, but it’s better than nothing.

 

For those using Chrome, there is a Tabs Counter plugin which performs the same task.

Hide your desktop icons

Why

My desktop inevitably is the dumping place for miscellaneous junk.  I’d rather just keep it out of sight and search with a program than keep it organized and visually scan through them for what I’m looking for.  Computers are a lot better at search than humans; let’s take advantage of that.  The icons on the desktop do nothing more than distract me.

How

Camouflage hides desktop icons
+ allows you to double click on the desktop to have a finder window popup for the desktop
+ allows you to change the desktop background
+ free

Desktopple
+ also has option of dimming the menu bar
– paid ($17)

I use Camouflage on both my home and work Mac.  I was happy to see that Windows 7 allows you to hide the desktop icons without installing an additional program.

Dim your menu

Why

Eliminate distractions by de-emphasizing the elements on the screen that are not important.  For the time you are not actively attending to the menu, make it less visually important.

MenuShade
– doesn’t seem to work in 10.5

 

MenuEclipse
+ Works fine in 10.5
– abrupt jump between dimmed and not dimmed – the menu dimming in DeskTopple is more gradual / less harsh

 

Standard brightness

Dimmed

I use MenuEclipse on both my work and home computer.  It’s not a life changing application but it does what it sets out to do.

Dim your unused applications

Why

When you have multiple applications jockeying for your attention, you necessarily lose focus

There are some obvious exceptions to this; for instance it is often extremely convenient to have both a calendar program and e-mail program open side by side when scheduling things, or having a web browser next to your programming environment for web search results.  There are other times in which such extra programs are a distraction; in this case having a single program as the focal point can allow you to focus.

How

Doodim
+ free
– does not interact correctly with Quicksilver/Alfred quick launchers
– noticeable lag when switching between windows
– no way of specifying the brightness
– seemingly not in active development
http://www.lifeclever.com/doodim-menushade-eliminate-distractions-on-your-mac/
– Ugly icon that takes up a huge amount of space

Think
+ Free
+ Much more polished than DooDim
+ Allows you to customize how dim the background gets
+ System settings stay bright
+ Works with Quicksilver/Alfred

O different interface than Doodim – you have to explicitly choose a new window to focus on via an interface similar to the standard task switcher, rather than being able to shift the focused window by clicking on other windows.

– Does not work with multiple spaces

I use think on a daily basis; in fact I am writing this article with all but my FireFox window dimmed out.  The higher your screen resolution, the more useful this program is.  When working on a 13″ screen I don’t often tile my windows too much.  But when you have a 30″ monitor or something similar, you can end up with many programs onscreen simultaneously.  And you might not want to put the program you’re working on full screen, especially if it’s just a text editor.  That’s when being able to have your programs the size you want and still be able to dim all the rest can be especially useful

Eliminate interruptions

The final piece in reducing distractions and improving single-minded focus is to remove the interruptions that our installed programs produce.

Turn off Growl notifications

If you’re unfamiliar with Growl, it’s a program which ” lets Mac OS X applications unintrusively tell you when things happen. ”  While it is a lot less intrusive than a traditional modal popup window, it still can be distracting.  The first thing you should do is close the programs that are creating the popups in the first place, but you might want the program to run, just not keep interrupting you.

I personally haven’t taken this step, but you can remove Growl if you find it too distracting.  Instructions are here.

Turn off e-mail alerts

E-mail clients on the Mac seem to think every e-mail that comes in is a matter of life and death, and that you absolutely must see every e-mail the instant it arrives.  Those of us who work in an office know that this is far from the truth.  As Merlin Mann writes:

Email is such a funny thing. People hand you these single little messages that are no heavier than a river pebble. But it doesn’t take long until you have acquired a pile of pebbles that’s taller than you and heavier than you could ever hope to move, even if you wanted to do it over a few dozen trips. But for the person who took the time to hand you their pebble, it seems outrageous that you can’t handle that one tiny thing. “What ‘pile’? It’s just a fucking pebble!”

While dealing with e-mail is a whole different issue, the least we can do is make sure that each pebble falls silently into the inbox rather than calling attention to itself.

Mail.app

Mail -> Preferences -> New mail sound: None

 

Entourage

How to turn off e-mail notifications in Entourage
Short version:
Entourage -> Preferences -> General Preferences -> Notification ->
Uncheck Display Alert, Bounce Icon, Bring Application to Front, and New Mail Sound

Thunderbird

Instructions on turning off e-mail notifications in Thunderbird

Conclusion:

This post was started long before Apple’s announcement of its new operating system, Lion, but it was not surprising to me that Apple is going to make OSX work more like iOS, with the addition of full screen applications and an app store.  I don’t want the Mac to become exactly like a giant iPhone or iPad, and I certainly wouldn’t want every application to be full screen.  However, there are times when I need to focus, and by making the computer less capable, it makes me more.

Synergy – free mouse/keyboard sharing across operating systems

November 11, 2010 2 comments

Any sufficiently advanced technology is indistinguishable from magic

-Arthur Clarke

I love technology.  I especially love discovering and using technology that makes me more productive.  I’m writing about a piece of software called Synergy that allows you to use one mouse and keyboard to control multiple computers, each of which may be running different operating systems.  In my case, my primary display is for my Mac, and a secondary display off to the right is connected to a Windows PC.  Previously, any time I needed to use the Windows machine I had to unplug the USB cable powering the keyboard/mouse combo and physically plug it into the windows machine.  (Alternatively I could have bought an extra keyboard and mouse and had to juggle with the physical hardware.) If I needed to transfer text (e.g. a sourcecode snippet) from one machine to the other, I would have to resort to shuttling files or e-mailing it to myself.

By using Synergy, the mouse no longer stops at the right edge of my Mac display.  Instead, the cursor continues to move to the right, onto the Windows desktop.  Suddenly both your mouse and keyboard control the PC.  If you copy text from a file on Windows and revert to controlling the Mac by moving the cursor back to the left, the text is in your Mac clipboard.

That’s not to say that Synergy is perfect.  The main problem is that certain key combinations on the Windows side do not transfer correctly.  For instance, Ctrl + Alt + Delete is pretty necessary in Windows land, but pressing those keys does not trigger the corresponding action.  The Synergy FAQ page has this issue at the very top, but none of the workarounds work for me.  I’ve noticed the following keys do not get sent over correctly:

Key combo Description
Ctrl Alt Delete Bring up task manager
Print screen Take a screen shot of desktop
Windows + Any other key (Windows L = Lock, Windows D = show desktop/hide all windows)

Other limitations I’ve seen are as follows:

  • Pasting is limited to plain text (e.g. you can’t copy an image from one computer to the other).
  • You can’t drag and drop files between the screens (this would be awesome); instead best workaround I can find is to have a networked folder accessible to both computers and use it as a dropbox to ferry around files.  It’s a bit kludgy but it works.

Each computer will need to install the software and be accessible on the same network.  The computer into which the mouse and keyboard are plugged should be the Server.  Each of the computers that you wish to control via the mouse and keyboard need to be running the Client software and connect to the server, and the server needs a configuration file which tells it how the screens are physically located (which computer is to the left of which, which is above, etc.)

Finally, there’s a bit of work you need to do to get it to work on windows vista/ 7 – see here for the details.

This is a really great piece of free software, and it allows me to do my job more effectively.  I hope you find it useful as well.

NetBeans Platform – how to customize the title bar and remove datestamp

November 10, 2010 6 comments

Problem:

When you create a NetBeans Platform project, the title bar includes a datestamp/version identifier which is visually distracting.  You’d like to customize the title bar.
Default title versioning

Right click on the project node, and choose Find.  In the dialog box, search for {0}.

In the results, double click on the first Bundle.properties, in branding/modules…

Replace the lines with {0} with what you desire the title to be:
relaunch the program.

Updated title bar

You can also change the title at runtime with the following code:
Frame f = WindowManager.getDefault().getMainWindow();
f.setTitle("My title");


These are modified instructions based off of a thread found here.  See instructions on how to change the versioning number, if that’s what you desire, here.

 

EDIT:

If you are attempting to change the window title programmatically from an Installer instance, you’ll find that this doesn’t work.  The problem is that you are changing the title too early in the lifecycle.  Instead, you need to do the following:

// Only change the window title when all the UI components are fully loaded.
        WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
            @Override
            public void run() {
                WindowManager.getDefault().getMainWindow().setTitle(windowTitle);
            }
        });

Bash: How to redirect standard error to standard out

November 9, 2010 Leave a comment

Problem:

You have a program which is outputting information to standard error that you wish to search through.  When commands are chained together in Unix via the pipe operator, standard out is connected to standard in.  Thus you cannot easily search the contents of the standard error.  How can you find what you’re looking for?

Solution

The first solution is to save the standard error as a file, and search through the file.

command_producing_standard_error 2> stderr.txt; grep "search string" stderr.txt; rm stderr.txt

This works but you have to remember to remove the text file that’s created in the process.

A better solution, and one that allows you to use the standard error in an existing pipeline is to instead redirect standard error to standard out.

command_producing_standard_error 2>&1 | grep "search string"

Recall that 2 refers to standard error and 1 refers to standard out; those familiar with C/C++ should recognize ‘&’ as the address operator, and it serves a similar role here.  After this command, both the standard out and standard error are in one stream, standard out, and can be connected via the pipe (|) symbol to other programs, such as grep.

This tip is modified from information found in the Bash Cookbook, in the recipe “Saving Output When Redirect Doesn’t Seem To Work”.  Additional solutions and discussion can be found on unix.stackexchange.com.

Categories: unix Tags: , , , , ,

NetBeans Platform – How to handle the working directory problem

November 9, 2010 6 comments

I have written previously about NetBeans Platform, but as a refresher or an introduction to my new readers, it’s a Java based framework for developing rich desktop applications.  A NetBeans Project is comprised of one or more modules.  The code in Module A cannot be accessed by Module B, unless Module B declares a dependency on Module A, and Module A explicitly declares that its code is public.  In this way, code is segmented and encapsulated into logical blocks.

In this example, I’ve created an example project, with three modules – one for the View, Model, and Controller.  (See Wikipedia if that’s not ringing a bell, and then my post about a Java Solar system for a concrete example implementation).

The project can be run either from the main project node,

or by any of the modules:

While in most cases, the behavior will be identical, there is one way in which the manner in which you launch the application matters enormously: relative paths.
The working directory is directly influenced by whether you choose the project or the module to launch with:
# Application launched from the ExampleApplication node:
Current Directory       = /NetbeansExample/ExampleApplication

# Application launched from the View module:

Current Directory       = /NetbeansExample/ExampleApplication/View

Why is this a problem?

Say my View code has a properties file it needs to read in to initialize some code.  Let’s say I store it at
/NetbeansExample/ExampleApplication/View/resources/example.properties
From within my sourcecode I might attempt to do the following:
File f = new File("resources/example.properties");
If I have started the application from the View module, then this will work fine; the current working directory is /NetbeansExample/ExampleApplication/View, as I previously said; thus by tacking on resources/example.properties, we come to a valid file.  If you launch from the main project, you will find that the file doesn’t exist, because /NetbeansExample/ExampleApplication/resources/example.properties does not exist.

How do can we handle this?

The best way I’ve found is through the use of the InstalledFileLocator class, provided by the Netbeans Platform Module APIs.

First, we need to move the .properties file from View/resources to View/release.

Once we have done that, we need to declare a dependency on the Module API in order to use this InstalledFileLocator class.  Right click on the View node and choose Properties,
In the libraries pane, click Add Dependency, and then start typing InstalledFileLocator.
The Module API should appear in the list.  Choose it and click OK.  You should see
From within your view code, you now replace code that looked like
File f = new File("resources/example.properties");

with

File f = InstalledFileLocator.getDefault().locate("example.properties", "net.developmentality.view", false);

where “example.properties” is the path to the file you’re trying to load, relative to the “release” folder, and where “net.developmentality.view” is the package name of the file in which you’re working.  The last argument is described in the Javadocs as:

localized – true to perform a localized and branded lookup (useful for documentation etc.)

I have had no problem leaving it false for my purposes.

Conclusion

I found this workaround after scouring the forums and being led to an FAQ about the LocalizedFileLocator.  It makes the code slightly more messy, but at least it works regardless of how the user or developer launches the application, which cannot be said for the standard way of specifying relative paths.  It is a very hard thing to search for, so hopefully someone running into this problem using NetBeans Platform finds this post.

Of Rubber Stamps and CheckBoxes: Why your Android ListView is broken

November 5, 2010 5 comments
There are a lot of tutorials on how to use ListViews, the ubiquitous UI element in which a list of information is presented in a linear, scrolling view.  However, I do not think they do enough at explaining just why they behave in the way they do, especially with respect to stateful UI components. 

An example list view, with a very simple "view" for each row

The problem is, people do not quite understand what it means for views to be reused in the context of a ListView. This blog post is intended to explain what that means, and what consequences that has for your list views and your adapters.

The following description comes from the Swing documentation on how JTables are rendered, but it is instructive for this description, and introduces the central metaphor that helps explain what’s going on with the way ListViews are rendered.

Before you go on to the next few tasks, you need to understand how tables draw their cells. You might expect each cell in a table to be a component. However, for performance reasons, Swing tables are implemented differently.

Instead, a single cell renderer is generally used to draw all of the cells that contain the same type of dataYou can think of the renderer as a configurable ink stamp that the table uses to stamp appropriately formatted data onto each cell.

Why would the designers implement the rendering this way?  Imagine if each row of the table (or list) were a separate object.  Each row would hold references to its own UI widgets, e.g. for TextViews (labels), ImageViews (images).  If there were N rows and each row takes on average M bytes of memory, you’d have an average memory footprint of N*M bytes.  Given that these lists need to be able to display a large number of items, this would be an unacceptable memory footprint.  Furthermore, since most of the list would be offscreen, most of the memory would be completely wasted.  While it would be simpler to implement, it would bring any Android phone to its virtual knees.

The designers, borrowing from the Swing designers, chose instead a much more memory efficient way of rendering the lists – if only X items are visible on the screen, where X is much less than N, the total memory footprint would be X*M bytes.  It takes more work in the ListView class to calculate exactly which rows are visible and to ensure that only their views are rendered, but it’s worthwhile.  Each visible row uses its own “rubber stamp”, filling in the details specific to that row. 

What you do by defining your adapter view in XML is define the raw features that make up your rubber stamp.

This is the basic rubber stamp that might be used for displaying tweets in a Twitter application.  There are four elements: an image, a username label, a paragraph text label, and another label for how the tweet was posted.
Let’s say that at most four tweets can fit on the screen at once.  When the first row needs to be rendered, the view is null (hasn’t been instantiated) and must be inflated from XML.  This process is repeated for the second and third row.  When the next tweet needs to be loaded on the screen, it can reuse the view (rubber stamp) of the view that’s just left the screen at the top.

Row views are reused

This leads us into what trips a lot of Android developers up.  You cannot maintain state within the UI components alone.  What do I mean?  You cannot use, for instance, Checkboxes in each row and hope to have them keep track of which items are checked or not.  Why?  This will work for a small number of rows, but once you get past the number that can fit on one screen, you’ll start to see weird problems.  If you can fit X rows on the screen, then item 1, X+1, 2X+1, … will all share the same checkbox.  Thus by changing the state of item 1, you will change the status of all the rows further down the line that are a multiple of X away from it.  The correct way of handling this is to have each row data object, that which is being visualized by the Adapter, maintain this state.  You can see an example of this in a tutorial on how to use checkboxes in listviews. I see this question come up repeatedly on StackOverflow, and it stems from the programmer not understanding how these views are reused in each row.
The metaphor of the rubber stamp fits more with that of JTable rendering, where there truly is a single component that gets reused over and over again, whereas there are multiple reused row View objects in the case of Android.  Why isn’t the single component approach used for Android?  At first I assumed it was, until I read this great explanation on android.amberfog which illustrates how there are actually as many views inflated as there are potential rows visible at any time.  The reason as far as I can imagine is that the user needs to be able to interact with each rows.  If all that was required was the static view of each row, then it would be fine to use a single rubber stamp, render a row, change an offset in the graphics context, and render the next row.  As it stands, however, each row needs to be able to detect when it is clicked on, long clicked on, etc.  Furthermore, each row could have UI elements which themselves could be interactive.  Thus it is insufficient to present static views of the data; the user would be unable to interact with the rows in the way he expects.
I hope this explanation is helpful, and if I’ve gotten anything wrong, I’d love to hear about it in the comments.

(All images were created with the use of Balsamiq, a great tool for mockups).