I've enjoyed a lot of things since switching to a Mac a few years ago, for all the typical reasons: It's intuitive nature, the relative security, the fact that most of the software you will need comes with the operating system, how well it works with the other Apple devices I've started to accumulate.

On the nerdier side of things, I've really enjoyed some of the under-the-hood tools that can be used to automate jobs that you find yourself doing over and over again.  As the macosxautomation site describes these features:

Sooner or later every individual, business, or organization is challenged to perform repetitive or complex procedures on their computers. Whether the task is renaming numerous files, batch processing images, or building documents using data from multiple sources, the need for powerful automation tools is shared by all computer users. Mac OS X is designed, from the ground up, for automation and offers a variety of integrated tools and technologies to solve your automation challenges.

In short, Mac automation gives the user the ability to create little computer programs that run certain jobs for you.  You can do this with a programming language called AppleScript, which is a verbose language where you can use simple English words to tell it what you want it to do.  I actually haven't spent a lot of time using this, however, because there is an even simple way to create your programs called Automator.  With Automator you can drag and drop instructions in a certain order to achieve your desired task.  For example, you could arrange instructions in this order:

  1. start with an image
  2. resize it
  3. rename it 
  4. save it in a certain file

I won't go into more detail than that as there are a lot of great rescource out there.

 

Now on to my recent problem.

I enter a LOT of data on my Web site, EyeDock.  I have some handy web forms that allow me to do this online in a nice tidy way (as opposed to having to always deal directly with the database).    However, a new part of the site is having problems with any quotation marks (") that I enter on these web forms.  Eventually this will be something I need to fix on the back end, but for now I really want to enter this data now.  If I 'escape' the quotes everything works fine, which means I have to type a front slash before every quote (\").  I found myself doing this about 50 times and I realized I had to find a better way.

One potential solution is to copy the text, paste it into a text editor, and then do a find (") and replace (\"). However, this solution didn't sound much more appealing to me than what I was already doing.  I wanted to do a find a and replace within my browser, but unfortunately browsers do not provide this option.  This was the perfect job for Mac automation.

I decided to make a service to find quotation marks and replace them.  Macosautomation describes services thusly:

The Services menu, found in the Application menu of most applications, offers a wealth of powerful automation options. In Mac OS X, many applications and system components publish their abilities as “services,” enabling the functionality of one application to be used with the items selected in another application. For example, using a Mail service from the Services menu, text selected within a Pages document can automatically be used to create a new outgoing message in Mail. Or the text of a long article displayed in Safari can be quickly summarized in a few concise sentences.

So, I opened Automator (found in the applications directory) and chose the 'create a service' option.

I knew I wanted the service to be available when text was selected, and I knew I wanted to replace that text. I'd be doing this online so I wanted to accept text from Safari, but I figured I might as well accept text from any application in case I wanted to use the service in another program.  So, so far I had these options selected:

 

Next, I had to do the search and replace.  Unfortunately this isn't one of the many options available for text manipulation in Automator.  Automator can, however, run scripts in other programming languages, including the aforementioned AppleScript.  Another option is perl.  I've become familiar with a lot of different languages over the years, but I've actually never worked with perl.  After some quick Google searches I found some examples that gave me a sense of how string substitutions work in perl and came up with this short script:

while (<>) {

$_ = ~ s/\"/\\\"/g;

print $_;

}

Which pretty much says go through the given text, and every time you see a quote ("), change it to an escaped quote (\").  The key is in the second line which uses a function that substitutes text like this:

~s/x/y/g;

Which means when you see an "x", replace it with a "y".  So, essentially, find whatever is after the first backslash and replace it with whatever is after the second backslash and before the last one.  The letter "g" at the end means global, which indicates you want this to be done on every letter "x" in the text (not just the first one).

 

So, if you want every instance of the word "hello" to be replaced with "hi" in this sentence:

"hello, my name is Todd, and I say hello"

You'd use this statement:

~s/hello/hi/g;

And get this result:

"hi, my name is Todd, and I say hi"

 

Unfortunately things get more complicated when you want to use special symbols.  Most computer languages use punctuation marks and other characters and it can be confusing if you want to use these things - the compiler needs to know if you're using these items as part of the language or if they're being used as your text.  

For example, I wanted to search for quotation marks (") and replace them with a frontslash (\) and a quotation mark.  If I followed the patterns we were using above it would look like this:

~s/"/\"/g;

However, both quotation marks and backslashes are reserved special characters.  To use them we need to escape them (which is exactly what I'm trying to do with my original text).  We'll do this by adding a frontslash not onlyin front of each quotation mark, but also in front of the frontslash!

~s/\"/\\\"/g;

So, even though it looks like my 1 year old started slapping at my keyboard, this statement actually has meaning.  These sorts of statements can actually get significantly more complicated, but can also be incredibly powerful.  To learn more do a Google search for "regular expressions".

 

So, my completed Automator script looks like this:

 

I saved it under the name "escape quotes".

 

Now, when I'm filling out these text fields in Safari, I can select the text, right click and choose services -> escape quotes.  All my quotes are automagically escaped and life is beautiful.  (As an FYI, I usually don't use Safari, but unfortunately this is the only browser that will work with services).

So, this is pretty simple stuff for a perl (or any other language, for that matter) programmer but I hope it might be helpful for someone without programming experience who wants to do something like this.  Of course you can search and replace anything you want, not just quotation marks.  If you're really ambitious you could create an automator script to ask you what you want to search for, what you want to replace it with, and then hit "go".  It would actually be a more robust service than hard coding it as I did, although for my needs (one simple task that I wanted done quickly) this worked well.

 

 

 

Posted
AuthorTodd Zarwell
CategoriesTech
4 CommentsPost a comment

Whenever I've read a biography I've always been struck by how much information they have about people that died 50, 100, or even 1,000 years ago.  Of course, most of the people that are biography-worthy were pretty great while they were living and therefore were more likely to have been written about by their peers.  And, as these individuals invented or created great things like masterpiece works of art, life changing inventions, paradigm shattering philosophies, etc., you can spend a lot of time talking about what they did and how their work affected our world.

On this day 150 years ago, Todd Zarwell, the inventor of Cottage Cheese Whiz, enjoyed a 9-piece chicken McNugget meal.

Some of our knowledge comes from public records.  For example, we know Copernicus was born to wealthy merchants and had the privilege of a good education. We know that Caravaggio walked around with a sword, looking for brawls, and killed at least on man.  However, it still always amazes me how much they know about the inner workings of these great people.  It really seems like we really know what made them tick. 

I realized a couple decades ago that, for many of these historic figures, much of what we know comes from their own words.  Sure, a few of them kept journals or wrote memoirs.  Still, the biggest source of information is often from their letters.  These people wrote a lot!  And, like anything that any skill that is repeated ad infinitum, they were really good at it.  

For example, Vincent Van Gogh was not a celebrated artist during his life.  On the contrary, he suffered from mental illness and had a hard time giving his paintings away.  His fame came after his death, and I suspect we would know very little about him if he hadn't exchanged over 600 letters with his brother Theo.  There are a few periods where little is known about Vincent's life: when he and Theo lived together and they had little reason to write.

Nearly every biography I've read has had a similar theme: Letters from the person, letters to the person, letters referencing the person.  The authors of the biographies try their best to fill in the gaps with their understanding of the culture and the times that their subject lived in, but these letters serve as the foundation for these life stories.

This has really made me think about our modern lives.  I haven't written a letter since 1994, and even when I did they were short and I divulged very little personal information.  What if I do something great (probably by accident), and they want to write about me a hundred years from now.  What will they know about me? Well, we have more public records than ever before, so they'll know where I went to school, how I performed in school, where I worked, if I was incarcerated (so far so good on that one), etc.  

But what will they know about me personally?  Well, we don't write letters like we once did because of the "improvements" in communications: telegraphs, phones, email, and now FaceBook and Twitter.  We have faster was of communicating nowadays, and, since we don't have to wait a month before our letter arrives at it's destination, we're a lot less likely to pour our deepest thoughts into our writings.  Instead, we write short emails and one-liner status updates.  

On one hand, my life is going to be very well documented as I often record what I'm doing, sometimes with pictures, video, and geolocation.  On the other hand, my deepest thoughts usually just bounce around inside my head and are only shared with the people closest to me.

What does this mean?   Unless I want my recorded history to be a list of where I've eaten lunch I'd better start writing more regular blog posts.

 

 

 

Posted
AuthorTodd Zarwell

Here's what my lunch looked like to me:

Pizza

My almost-three-year-old looked at his slice of plain pepperoni 'za, looked at my piece, and looked back at his again.  Apparently my pizza looked like this to him:

Snake Pizza

because he asked me if it was snake pizza.

The funny thing is, he didn't say it like it was a gross thing or a scary thing. His tone didn't suggest that he would be unwiling to eat it.  He just wondered if it was snake pizza.

Posted
AuthorTodd Zarwell

Here's a mystery that took a little time for me to solve.  First, a little background: On February 14 we got the kids a couple helium balloons that had little weights at the bottom of them.  More about that later.

So, I put Mason (9 mo old) on the floor of his and Drew's bedroom because I had to run to the rest room (except I call it the bathroom).  I put one of the Valentine's balloons near him just to keep him entertained.  When I returned from the bathroom I noticed that Mason was sitting in a pile of rice.  It was almost surreal - I was sure there was no rice there a couple minutes ago. Could I have missed rice on the floor? I don't think so.  And why would it have been there, anyway?  Could we have a Chinese poltergeist?

I thought about my older son at daycare.  When he was a little younger they would have "sensory tables" where they would have a recessed table filled with things that would provide a different sensory experience: water, dirt, even coffee grounds and flour.  Sometimes I'd bring him home from school and these things would fall out of his pockets and diapers throughout the evening.  Could they have had a rice sensory table in the infant room? Would they really give babies raw rice?  It didn't sound like a very good idea, but even if they did, this was a LOT of rice.  I couldn't fathom that there had been this much rice in his diaper and I hadn't noticed it before now.

I'm sure anyone watching would have described me as the poster child for confusion as I dazedly looked around the room seeking an explanation for the sudden appearance of the cylindrical grains.  I left the room and returned at least a couple times thinking I'd come up with an explanation for this. Eventually my eyes came across the Valentine balloon across the room and against the ceiling.  That balloon had had a little bag tied to its string to weigh it down. I didn't know exactly what was in the bag weighing it down before, but now I suddenly did: rice.  Sure enough, the bag was still tied to the sting but it was now open and empty.  

I was mostly relieved, because I didn't have to completely rethink my understanding of the natural world to explain spontaneous rice generation.  I just lived in a world where curious babies could destroy things, including a balloon's ballast.  The fact that babies could destroy things was already known to me, and suddenly everything made sense again.

I picked Mason up and left the room.  When I got a chance I went back to clean up the rice, but another mystery had developed: most of the rice had disappeared.  However, this phenomenon, while on the surface appeared paranormal, was immediately explained: the dog had ate it.

Posted
AuthorTodd Zarwell

On the way home last week my 2.5 year old declared that lions hang upside down under water.  I told him that I didn't think that was true, but he immediately said it was.  This was one of those times where I realized he was confident in his statement and any attempt to make a reasonable argument would be met with steely resolve.  

The more I thought about it, however, the more I liked the idea of a lion hanging upside down in the water.  I decided to draw a picture, first on a napkin and then a fancier illustration.  Here is the result (click to see full picture):

click for full size

 I like to paint, draw, and illustrate, but it's hard to find inspiration.  I now have a new muse, my little boy.  There will never be a shortage of great ideas!

So, I'm curious - how would you explain this picture?

 

Posted
AuthorTodd Zarwell

I came across an iPhone app last week that I've grown to like quite a bit.  It's called Handoff.

Let me set the stage for you:

You quickly look up a recipe on your computer and decide you need to run to the store to get the sesame oil, quinoa, chicken gizzards, and all the other ingredients to make your exotic five star meal.  

HandoffOr, you come across an interesting article right at bedtime. You really want to read about the epidemic of recent salamander attacks but just don't want to do it at the kitchen table at 11:30 at night.

Or, you call up a Google map with directions to the house of the local weather person.  You decide now is the time to head over to their place, peek in their windows, and perhaps let them know that you did receive the secret love message that they sent over the newscast.

Sure, in all these cases you could do the search again in mobile safari on your iPhone or iPad.  Or you could email yourself some of the information.  

Or, you could use Handoff! [pause for applause]

To use Handoff you need to download the Handoff app onto your iPhone and/or iPad and then add a handoff extension to your Chrome or Safari browser (or a bookmarklet, if you're using Firefox or IE).  These can be found at the Handoff homepage.  Then, when you come across something interesting on your home computer you simply press a button in your browser and you get an instant notification on your iOS device that that Handoff has received the item.

If you've sent a web page it will open up that web page.  If you sent a map it'll open the map.  If you had highlighted any text it'll send that snippet to your phone.  If that text was a phone number you'll be able to tap it and make a call.

In summary, it's a very simple utility.  However, any time I can avoid writing something down, searching for something more than once, or just accomplish a ask in less steps, well, it makes me happy.  

 

Posted
AuthorTodd Zarwell
TagsApps

A while back a friend wrote a FaceBook status stating:

My three year old is going to have awesome abs - he does planks constantly

 My response:

That's incredible!  Most kids dont grasp quantum mechanics until much much later!

Planck's planksAt this instant I had a self-image of myself as a very bright and funny guy. I was the Jim Carrey of nerds.  I patiently sat and waited for the responses addressing how clever I was to associate "planks constantly" with  "Planck's constant".   And waited.  And waited.  Alas, they never came.

I actually didn't quite remember exactly what Planck's constant was, so I looked it up quickly in Wikipedia:

The Planck constant (denoted h), also called Planck's constant, is a physical constant reflecting the sizes of quanta in quantum mechanics. It is named after Max Planck, one of the founders of quantum theory. The Planck constant was first described as the proportionality constant between the energy (E) of a photon and the frequency of its associated electromagnetic wave (ν).

I briefly though that perhaps I should post this text to the Facebook status.  Then people could finally appreciate my rapier wit.  

comic book guyAs a little more time passed my self image started to degenerate.  Maybe I wasn't the Jim Carrey of nerds. Maybe instead I'm the comic book guy from the Simpsons.  An annoying, condescending geek who makes jokes and takes pleasure from the fact that most people around him aren't going to understand.

 

Sigh. 

It's not easy being nerdy.

Posted
AuthorTodd Zarwell
Tagshumor

I was listening to the This Week in Tech podcast this past week when panel member Brian Brushwood mentioned a magazine that fueled his interest in technology as a child: Enter Magazine.  Although I don't officially work in a technology profession or surround myself with technology people, I've never heard anyone mention this magazine before and I was beginning to think I was the only one that ever subscribed to it (which might explain why it only lasted for 17 issues).

Issue # 1 Oct 1983

The mere mention of Enter magazine brought back a flood of fond memories. I'm not sure where my mom heard about the existence of this magazine, but she must have thought it would appeal to me because it arrived in our mailbox one day.  I was hooked, and could barely wait until I received my new edition each month.  

I have fond memories of taking the magazine to school and typing in BASIC programs, line for line, into the the classroom Apple IIE.  Once I the program worked I'd start modifying it and customizing it to do and say the things I wanted it to.  This was the perfect way to learn programming, perhaps the ONLY way: my small parochial school didn't have programming classes.  Furthermore, BASIC programsI don't recall ever encountering a book about programming during my childhood, and of course the Internet didn't exist, at least not outside big universities and the military.   The only way a kid in small town Wisconsin could learn to program was to see BASIC commands in a magazine and then spend countless hours experimenting with them to to learn how to unlock their full potential.

One day my mom got a letter from Children's Television Workshop that said Enter Magazine was no longer going to be published.  In it's place I would receive 3-2-1 Contact Magazine, which would have an "Enter" section.  Needless to say, I was dismayed - I'd seen 3-2-1 Contact at school - it was OK as every kid was fascinated with the red-eyed day-glo tree frogs that always seemed to be on the cover, but it wasn't going to compare to Enter.  I was devastated. 

So, when Brian Brushwood mentioned this publication I was filled with nostalgia.  I did a Google search and found almost nothing for "Enter Magazine" - very disappointing.  Enter on the iPadHowever, there was a short Wikipedia article. This article linked to a Web site called retromags, which seems to be a place where people can upload old magazines. To my surprise, there were images of all 17 issues of the Enter covers.  Even better, all the pages of every issue were downloadable.  With a little finagling I was able to download them onto my iPad.  I was thrilled at this accomplishment, despite the fact that it merely induced my wife to sadly shake her head.

While browsing the premier issue of Enter I'm reliving the excitement of my 11 year old self.  Some high points from this issue include:

  • Can Computers Go Crazy? The reality behind "WarGames" and "Superman III".  Includes an interview with Matthew Broderick.
  • Video Games: The Falls Biggest Hits.  Includes Atari versions of Ms. Pacman, BurgerTime, Qix, and Centipede.
  • Moving Maps. "You're driving along in a car, and you make a quick turn. Guess what?  YOu're lost.  Instead of pulling out a road map, though, you push a button.  A 6"x8" screen above the radio instantly shows a map .. but what's that triangle moving along the screen?  Your car!".  The article goes on to explain how this device pulls down information from a satellite and might be available in 5 years.  That would have been 1988 - I don't remember having GPS during the Reagan administration!
  • Buying the Right Computer.  Choices range from a $50 2k RAM Timex /Sinclair with only cassette tape storage [this was actually my first computer] to a $199 64k Commodore 64 to a $1265 64-512k IBM PS (who would need all that RAM?).
  • Progress Report: Video Discs.  Video discs look like silver record albums played on futuristic record players, but with a video disc player you get sound and video.

Ah, the memories!  Did anyone besides me subscribe to Enter?

 

Posted
AuthorTodd Zarwell
CategoriesTech