Display recursive directory listing in Terminal

Selecting List view in Finder displays files and folders in a recursive structure with sub folders and files appearing under their parent directories.

If you work in “Terminal”:terminal with any regularity, you know there are times when listing a directory structure in a manner similar to Finder’s List view would be handy, but there is no built in command to do so.

Before I switched to Mac OS X, I used Linux where I discovered a package called “Tree”:tree. The package consists of a single command that when passed a directory, displays a recursive tree-like listing of its content in ASCII form. The source for the package is freely available and can be downloaded and built in just a couple minutes.

Building Tree for Mac OS X

The following steps assume:

  1. Your using Mac OS X 10.6 Snow Leopard
  2. The latest “Xcode Tools”:devtools from the Snow Leopard DVD or downloaded from “Apple”:download are installed
  3. Your shell’s PATH variable includes /usr/local (if you don’t know why or how, see this Hivelogic “post”:hivelogic)
  4. You have experience running UNIX commands in Terminal

Change to or create a directory where you can download and unpack the source. I keep a ‘Projects’ folder to use for this kind of task.

cd ~/Projects/src/

Download and unpack the source code

The links and versions are current at the time of this writing. See the program “site”:tree for up to date information.
 

curl -O ftp://mama.indstate.edu/linux/tree/tree-1.5.3.tgz
tar xzvf tree-1.5.3.tgz

Now change to the source directory:

cd tree-1.5.3/

Modify the Makefile for Mac OS X

The source ships with a file called ‘Makefile’ that contains information used by the build process to compile Tree. By default, the source builds for the Linux OS and installs to /usr. Use your favorite text editor to change the file for Mac OS X.
 

Find the line that reads:

prefix = /usr

… and change to:

prefix = /usr/local

Find and uncomment (remove the leading ‘#’) the CFLAGS and XOBJS lines in the Mac OS X section of the Makefile so it looks like this:

# Uncomment for OS X:
#CC=cc
CFLAGS=-O2 -Wall -fomit-frame-pointer -no-cpp-precomp
#LDFLAGS=
XOBJS=strverscmp.o

Compile and install

make
sudo make install

Assuming you did not receive any errors during the build process, you should be able to type the following and see a recursive listing of all the files and folders in the current directory:

tree

If you want to see directories only, try this:

tree -d

That’s all there is.

[terminal]http://en.wikipedia.org/wiki/Apple_Terminal
[tree]http://mama.indstate.edu/users/ice/tree/index.html
[devtools]http://developer.apple.com/technologies/xcode.html
[download]http://developer.apple.com/devcenter/mac/index.action
[hivelogic]http://hivelogic.com/articles/using_usr_local/

Use Mac OS X Automator and Services To Speed Up Repetitive Tasks

“Automator”:automator is one of best kept secrets in Mac OS X. It’s kind of like drag-and-drop scripting that lets you create workflows to automate and speed up repetitive tasks. In Snow Leopard, you can use Automator to create your own services that are accessible via the Services menu and can also be contextual, showing up when you right-click on an item like text selections or files and folders.

The Automator application lets you build a workflow by choosing from a collection of actions, some native to OS X, some installed by other applications, and dragging those actions into a workflow. There are actions that perform standalone tasks like copying a file to a specific folder, processing an image, or asking for input. If you need something more advanced there are actions that let you run shell commands, or even call other scripting languages like Python, Perl, or Apple’s own AppleScript. Combining these actions into a workflow lets you automate just about anything.

Addressing an Envelope Using Selected Text
I recently received a request to mail some additional information for a rebate I submitted several weeks ago. The email message contained the mailing address for the fulfillment center. Ordinarily, this means either hand addressing an envelope or going through several steps to launch Pages, choose a template, cut and paste the address, and print the envelope. It felt like I should be able to select the address and have an envelope automatically prepared and ready to print, but there is no built in way to do this.

Using Automator, I created a service that appears as a contextual menu item when working with selected text… in this case an address. In this workflow the Automator service is essentially a wrapper around AppleScript which does the heavy lifting here.

Automator envelope workflow

Here is the AppleScript that makes it happen.

on run {input, parameters}
	-- set the name of Envelope template to use
	set theTemplate to "Classic Envelope"
	-- set selection to first item of input list, ignore rest
	set theSelection to item 1 of input as text
	tell application "Pages"
		-- launch Pages without "Template Chooser"
		launch
		try
			make new document with properties {template name:theTemplate}
		on error
			-- display msg if the template does not exist
			display alert ¬
				"Template does not exist or
the document could not be created" buttons {"Cancel", "OK"} as warning
			-- If can't create document, then bail out of the whole shebang!
			quit application "Pages"
			return
		end try
		tell the front document
			--delete the default template text and make a new paragraph
			delete every paragraph
			make new paragraph at beginning
			tell body text
				-- put the selected text into the new paragraph
				set paragraph 1 to theSelection
			end tell
		end tell
		-- open the print dialog ready to print! Enclose in try block to ignore errors
		try
			print the front document with print dialog
		end try
	end tell
	return input
end run

Download All Links on a Web Page
There is a great add-on for “Firefox”:ff called “DownThemAll”:dta that lets you download all the links on a web page without the need to click on each link individually. I have not been able to find anything like it for Safari. I wanted to download several zip archives containing sample code for a tutorial I was working through and was certain this could be done using Automator. In just a few minutes I hacked together a workflow that finds links on the current Safari page, filters them by extension, and displays a list for me to select from, before downloading the links to the Downloads folder. This workflow makes use of several Safari specific actions.

Automator download all workflow

Copy or Move Files and Folders to iTunes
One of the easiest ways to add songs to iTunes is by copying audio files or folders containing songs to the aptly named Automatically Add to iTunes folder. While this is relatively easy, why not save a few mouse clicks and drags by adding a service to the contextual menu for Finder items like files and folders. Add one service to copy files or folders, and a second to move them.

Automator copy to iTunes workflow

I have services that copy and move files to my “Dropbox”:db folder, create tar archives from selected files and folders, and even automatically shorten a selected URL with “bit.ly”:bitly. Automator includes actions for working with text files, creating PDF documents, and even processing images. There is really no limit to the cool things you can do with Automator.

Resources
There are lots of great places online where you can find workflows. The best place to start is at “Mac OS X Automation”:osxautomation where you will not only find sample services, but some great tutorials about Automator and AppleScript.

Using Automator to build workflows is simple and takes little time to learn. Services are an effective way to automate repetitive tasks that save time. Make your computer work for you now by creating a few services of your own.

[automator]http://support.apple.com/kb/HT2488
[ff]http://mzl.la/dUTkIB
[dta]http://bit.ly/emqgQS
[db]http://db.tt/SVZWzX3
[bitly]http://bit.ly
[osxautomation]http://www.macosxautomation.com/services/download/index.html

Blogging from TextMate

I have _reluctantly_ been using “TextMate (TextMate)”:tm for a couple weeks. No text editor can ever take the place of “Vim”:vim, but there are several features that attracted me to “TextMate”:tm. So far I am impressed, and “TM”:tm makes editing HTML(HyperText Markup Language) and CSS(Cascading Style Sheets) a snap.

I will write about my experiences when time permits, but for now how about this… “blogging from”:blog “TextMate”:tm. That’s right, this post was written and posted from inside “TM”:tm!

[tm]http://macromates.com/
[vim (Vim)]http://www.vim.org/
[blog (Screencast: Blogging from TextMate)]http://screencasts.textmate.org/blogging_take_two.mov

Urban Adventures in Portland

Portland is a fantastic place with a wealth of fun, exciting, unique activities that require little planning, little money, and little time. The weather was absolutely gorgeous this past weekend so we embarked on a couple of these “urban” adventures.

On Saturday my wife and a friend joined me to take on the newly inaugurated 4T Trail (map). The loop weaves though southwest Portland by trail, tram, trolley, and train, revealing some of the most beautiful scenery and views in the city.

 

We hit the trail at Washington Park making a moderately steep, but relatively easy climb about 2 miles to Council Crest Park. The park is Portland’s highest point and on a clear day offers incredible views of the surrounding area to the southwest, and Portland International Airport to the north.

At the center of the park lies a great compass made of inlaid stone. The compass has a unique acoustic effect; while standing at the compass’ midpoint, even softly spoken words reverberate all around you.

 

After enjoying the views, we were off down the other side of the park, over trails through some of the prettiest forests and neighborhoods in Portland.

Completing the second half of the trail, we emerged at the northwest side of OHSU and made the short walk a couple blocks to catch the tram. The tram took just a few minutes to carry us down to the waterfront offering a little time to enjoy a view of the cityscape to the north, and surrounding areas in all directions.

 

 

At the bottom of the tram, we waited a short time to board a Portland Streetcar and make the 10 minute ride to SW Morrison and 10th.

We were pressed for time so we headed straight to the stop to catch our train back to our car; otherwise, this would have been a good time to grab lunch. After just a few minutes, our train arrived and we returned to the parking lot at the Oregon Zoo.

The 4T Loop was incredibly fun and made for a wonderful 3.5 hour adventure on a wonderfully sunny and warm afternoon. Total cost was a whopping $2.00 for the public transit segments.

Sunday evening the whole family visited Northwest Portland to watch the Vaux Swifts roost in the old brick chimney at Chapman School. Each year during the month of September, these little birds return to Portland on their way to the warmer climates of Central and South America.

We arrived about an hour before sunset, and found parking a few blocks away from the campus and neighboring Wallace Park. There was a huge crowd gathered on the field and grassy area at the southwest corner of the school, where there is a clear view of the chimney at the rear of the building. It’s really quite a spectacle with a couple food cart vendors and kids with cookie stands serving the lively crowd.

Within a few minutes of arriving the birds began to appear, resembling dark, moving clouds or swarms of bees. Every couple of minutes a group would approach flying erratically, dive toward the chimney, and then dart away as if testing whether it was time to go in.

 

The groups began to combine making larger, and larger swarms, circling the chimney like a tornado. A hawk appeared, swooping into the middle of the birds, trying to grab a small swift for dinner but was repelled and chased by a flock that by this time consisted of thousands of birds.

Just a few minutes after sunset the large flock swirling over head, as if cued by someone or something, began diving into the chimney like they were being poured from a pitcher. It is a truly incredible site. And the hawk? He found his opportunity, returning twice to pick off a little bird just at the top of the chimney.

Video featuring the few last minutes of the swifts pouring into the chimney including the hawk assault.

Fabulous weekend in the Rose City.

Posted via email from meanderings

Google Voice: Transcription Near Misses

https://i2.wp.com/www.google.com/voice/resources/4232368305-voice_logo_sm.gif?w=525 I love the idea behind Google Voice, and appreciate the rich set of features, but transcription frustrates me. Sometimes the transcription feature is relatively useful, but more often than not the resulting text can be very odd. Here’s a couple examples:

I work to get rid of the quest secret given some Democrats are out in Los Angeles… I just put in an extra character deflator so if it’s confidential that I have an extra C and then not all.

 
What ever you do, don’t let the Democrats in LA get the quest secret. Use a character deflator if you need to.

I am with Thomases old breast and Shauna said she’d been worked with you.

Sounds a little personal to me, and I never even met Shauna.

Both of these messages were left by people who spoke English, had no accent, and sounded clear when listening to message. In all fairness these are extreme examples, but much of the time the transcriptions are of little use.

What really frustrates me, is that one of the primary purposes of Google 411 was to harvest terabytes of voice data and improve voice recognition technology. In an Infoworld interview nearly 2 years ago Marissa Mayer, Google’s Vice President of Search Products & User Experience said (emphasis mine):

Whether or not free-411 is a profitable business unto itself is yet to be seen. I myself am somewhat skeptical. The reason we really did it is because we need to build a great speech-to-text model.

Presumably, this “great speech-to-text model” is behind the transcription feature.

Google Voice is a newer service, but Google acquired Grand Central two years ago, and this is the best they can do? Admittedly I am complaining about a free service, but come on! I am a huge fan of Google’s many services and frankly have become a little spoiled by some of their other offerings that are so very good.

Voice mail transcription done well would be an incredibly useful productivity tool, and hopefully Google improves transcription quality in the near future. In the mean time, Transcription useful? No!

I invite you to share some of your most useless Google Voice transcriptions in the comments.

Posted via email from meanderings

5 Tips to Improve Your Running Experience

Running is a great way to stay in shape, and can be an integral part of a healthy life style. Almost anyone can do it, it doesn't require much in the way of equipment, it is inexpensive, and it can be done just about anywhere. But if your approach to running is that it's just a way to stay in shape, that it's a means to an end, it can feel like a big chore. If this is the way you view running, you often have to mentally psych yourself out, just to drag yourself out the door.

Over the past few years, I have struggled to run with consistency and found many periods where running seemed unappealing and difficult. My runs during those times were some of the most difficult physical experiences of my life. I recently tried to evaluate why I felt this way, and developed some practices that have helped me improve my running experience. Some are simple, some take a little bit of work, but all have the potential to add to the enjoyment that can be found when you unbind your body and run for your life.

Disclaimer: Before we start let me say that I am a neutral runner, with negligible bio-mechanical deficiencies. I am 45, and in good health. I am not a medical professional, nor am I a professional athlete. Don't start any exercise program without first consulting with your physician. These tips work for me, but your mileage may vary.

Loosen up. I used to stretch for several minutes before every run; quads, hamstrings, calves, back. Since improving my overall running form, I have found that simply loosening up my joints is much more effective. Start by rolling your neck, making big loops with your head. Shake out your wrists, arms, and shoulders for a few minutes. Pretend you are doing a hula-hoop to loosen up you hips and knees. Finally, "draw" circles over the floor with toes pointed to loosen the ankles.

Set Time-based Goals
. Unless you are training for a race, decide how long you want to run for and do it! Don't worry about pace, don't worry about distance, just run for the amount of time that feels good. You always have time to improve your stats.

Eat Right and Rest. Common sense, right? I can't tell you how many times I have gone to bed at midnight over several consecutive nights, run at 6am in the morning, and had a thoroughly miserable experience. Then there are the times when I eat fast food, or ice cream, or load up on cookies and run the next day, all the time wondering why running is so hard. Surprise! The amount of rest you get, and the composition of your diet play a huge role in how you feel when you run. Limit food to whole grains, soy protein, lots of fruits and veggies, legumes, and nuts. Eat sensible portions at meal time and limit snacking. Oh, and no soda… it just bloats and dehydrates.

Run Because You Enjoy to Run. You may want to lose weight, you may want to improve you cardio-vascular health, you may want to increase your aerobic capacity, but if you don't enjoy running, it's work. Find a way to love to run and the rest will come. Find fun places to run, change up the scenery now and then. I have taken to trail running lately, spending lots of time in a local park on several dirt and bark dust trails. I have a renewed appreciation for the beauty that surrounds me, I can focus on my thoughts, and virtually eliminate the feeling that running is a chore.

Run Barefoot
. C'mon, you know you want to! It makes you feel like a kid, and kids are natural runners. There is some recent research that suggests that running shoes with all their padding, motion control, and stability features actually enforce inefficient bio-mechanics making running more difficult and may even increase your  chance of injury. I take a few short runs in my Vibram FiveFingers each week; they give me the feeling and control of running barefoot, with the protection of a thin rubber sole.

photo via flickr.com

Take it slow in the beginning, your feet and calves will take some time to adjust and strengthen… after all, they have been pampered by thick padding and cushioning for years! Running barefoot will go a long way toward improving your form even when you run wearing shoes.

Just remember, you were made to run. There is nothing like the feeling that comes from running a few miles. Go, have fun!

Posted via email from meanderings

Thank Goodness for Smart People

It's amazing what creative, smart people come up with. Learn how CAPTCHAs are being used to digitize books; if you don't know what a CAPTCHA is, the video explains (you probably have used them many times). This clip is a little long, but very interesting and actually kind of entertaining, in a geeky sort of way!

How important is this technology? Google recently acquired reCAPTCHA for an undisclosed amount.

Posted via email from meanderings