» Remotely controlling a Mac at home: e-mail style!

Wouldn’t it be great if you could restart your Mac at home or find its IP address just by sending an e-mail?  I got the idea for this from Cory Bohon’s article at TUAW (read) written back in April on the same subject.  I liked the idea of being able to send a simple e-mail message and having my Mac mini do some task.  It’s a lot quicker than firing up a VNC or SSH session and doing it the long way.

First I would like to begin by explaining the problems I had that needed resolution:

  1. My Dyndns Dashboard widget is supposed to automatically update Dyndns with the public IP address at home where my Mac mini lives.  Sometimes (rarely [only once]) the widget will hang and Dyndns will not get my latest IP address resulting in 404 when I try to access the various sites running on the mini.
  2. I have an applescript application that will remotely update my Plex library as well as a cron job on the mini that will do the same thing locally.  Occasionally running this script, either remotely or as a cron job, will cause Plex to crash – no idea why.
  3. Sometimes I just need the blasted thing to restart.  It’s OS X, not God.

I’m going to go through these in order of the easiest to tackle to the most difficult.  Also, I’m only going to cover the scripts I created themselves, you can read Cory’s article for setting up the mail rules; he does a lot better job than I at explaining it.

Here is the script I used to call up Plex.  It’s incredibly simple and really speaks to the ease of Applescript.
tell application "Plex"
end tell

Yup, that’s it.  Simple, yet powerful.  All I have to do is send off an email and boom Plex launches.  Definitely quicker than loading up VNC and doing it through the GUI remotely.  This is especially true given that VNC is somewhat bandwidth heavy and can be slow to respond if the client or server have a lot of network traffic with which to compete.

The article I referenced above has a script for restarting a remote Mac; however, things can go haywire if you have an app that won’t quit.  Some people commented on Cory’s article and mentioned his script would not work if Safari was open with multiple tabs, and they are correct.  In my case I have Transmission running and it wants the user to confirm a “quit” before complying.  I had to find a way around that as it was preventing the script from being useful.  Without further adieu here is the script:
set pwd to "YourPassw0rd"
set cmd to "shutdown -r NOW"
do shell script cmd password pwd with administrator privileges

Pretty cool, only three lines for this piece of magic.  The first line creates a variable “pwd” for storing your password.  This is necessary because OS X only allows a user with administrative privileges to run the shutdown command.  The next line creates a veriable “cmd” that stores the Termainal (UNIX shell) script we will run in line 3.  If you open up Terminal.app and type in “shutdown -r NOW” you will be told the command cannot complete because you aren’t a super user (sorry mate).  Luckily, though, in the terminal you can append “sudo” to the beginning of the shutdown command to run it as an administrator.  The result is that the shutdown command will reboot (-r flag) the Mac at a specified time (NOW).  For information on sudo and shutdown check out here and here, respectively.  The last line is a whirlwind of coding genius; actually, not really.  It basically runs “sudo shutdown -r NOW” and passes in the password we used on the first line.  Thanks go to Cory for helping me to figure out passing in the password for another script I have.

The last problem, getting my IP address e-mailed back to me, was the hardest to figure out and is the “kludgiest” of the three.  The short version is that an Applescript calls another Applescript, fancy.  Actually, it’s Leopard’s fault; Mail 3 does not process mail rules with Applescripts the way it did previously in Tiger and earlier versions of OS X.  It used to be that the Applescript that gets called could actually reply to the message which triggered the rule; however, that is no longer the case and Mail limits what can and cannot be done in the Applescript.  Unfortunately, I don’t know what these limits are sufficed to say that what I need to do is not permitted.

OK, here we go; the Mail rule calls a script which looks like this:
do shell script "osascript /Users/Aron/Scripts/HomeIP.scpt"
That script says run the Applescript found at this location.  The script it calls, the one that gets the IP address and emails it, is here:
set cmd to "curl -s http://www.whatismyip.com/automation/n09230945.asp"
set my_ip to (do shell script cmd)
set my_dest to "youraddress@somedomain.com"
set my_subj to "My IP at home"

tell application "Mail"
GetURL ("mailto:" & my_dest & "?subject=" & my_subj & "&body=" & my_ip)
tell application "System Events" to keystroke "D" using command down
end tell

So this one is a little meatier, but if you’ve made it this far I would be remiss to not go further.  The first line is fairly obvious, it stores a Terminal command we’re going to use later; if you copy that command into the terminal and run it the output will be you current public IP address.  It atually took me awhile to find out whatismyip.com provided that neat little service.  Before I finished the script I was using a combination of sed and awk to format my curl output.  Anyways, my loss is your gain.  The next line takes the standard output from the command that we called “cmd” in line 1 and stores it as a variable called “my_ip”.  Next, we initialize and set two more variables – “my_dest” gets the e-mail address to which you want your IP address sent and “my_subj” stores the subject of e-mail which will be sent.  I could have used my_ip as the subject of the email, but for my purposes I prefer a pretty subject with the IP address in the body of the message.

The next part of this script launches Mail (if it is not already launched) and has it load a “mailto:” URL.  The URL gets dynamically created based on the variables we used above so the URL actually ends up looking like this:
"mailtoo:youraddress@somedomain.com?subject="My IP at home"&body=someIPaddress".
When Mail loads that URL it actually creates a new mail message with the properties (recipient, subject, body) we specified.  After that it uses Universal Access to automagically press “shift+command+D” to send the message we just created.

All in all, a pretty useful set of scripts if I do say so myself.  Hopefully someone will find this helpful to them.  If you know of a better way to make Mail send an e-mail any way other than my kludge-tastic Universal Access method feel free to let me know!

» iTunes 8 and the ridiculous hardware requirements

I knew Apple hated you if your hardware was old, but I didn’t think iTunes hated you too!  Apparently, if you want to watch HD TV shows using iTunes you are going to need at least a 2.0ghz Core 2 Duo processor.  Now I don’t know about you, but 2 of my 3 Macs (purchased within the last 2 years) do not meet this requirement.  And to be perfectly honest, I’m a little offended!  One of the two is a 2-year old MacBook PRO.  The Applecare hasn’t even expired on that bad boy and already I need to upgrade if I want to watch HD on it.  Wow.

I plan on doing some further testing of this to verify, hopefully the dire warning is all smoke and mirrors.  If there is a true limit I may need to go ape on somebody’s face.

UPDATE: News of iTunes 8 ridiculous hardware requirements were greatly exaggerated.  I tested HD TV shows on a 1.83ghz Core 2 Duo Mac mini and a 2.0ghz Core Duo MacBook Pro and in both cases the episode played without issues.

» Google Chrome brings excitement for all

The early announcement of Google’s Chrome project details have brought tears of joy excitement to the World Wide Web.  I am extremely intrigued by the idea of a multi-process browser; I cannot express the frustration I have when FireFox crashes because of some rogue website or Safari slows to a crawl because of all of the tabs that have been opened and closed.  Google’s Chrome hopes to solve many of those problems by bringing a new open source game to the playground.  Many of the exact details are pretty scarce so far but what is known is brought to us courtesy of a 38-page comic created by Scott McCloud.  I’ve posted a link to my hosted version of a PDF containing all of the pages.  Enjoy.

» Now Featuring Pretty Permalinks!

In case you weren’t already aware this site or blog, whichever you prefer, is running on Mac OS X Leopard 10.5.2 (not server) and is powered by the WordPress blogging engine.  Because this site is running on a simple Mac mini with Apache enabled the project is extremely “DIY” and as such I have had to figure it out as I go along.  No fancy hosts or one-click installs here, everything has been extremely manual; except, of course, the Famous 5 minute WordPress Installation!

One hurdle I have had to overcome is being able to use pretty permalinks to make my site more friendly.  Permalinks (short for permanent link, get it?) is a static URL to some content on a site.  That content can be a specific page, a particular article/post, or a collection of posts within a certain category.  

By default WordPress’s permalinks follow this format: http://somesite.com/index.php?p=1 and unfortunately that format is just plain ugly.  Having a pretty permalink like this: http://somesite.com/2008/01/01/sample-post/ means hyperlinks on your site and around the web will be more attractive and usable to others.

Read on if you want to know my story about the trouble and success I had with getting pretty permalinks working on my site.

Continue reading “» Now Featuring Pretty Permalinks!”

» iPhone 3G unboxing pictures, now with more indecisiveness

iPhone 3G

Ameoma.com has posted what seems to be the first set of unboxing pictures featuring TWO iPhones 3G of differing color.  Impressive, somebody is doing very well for themselves!  And since I am still unsure with what color I am going to go (you don’t know either!) I thought it would be good to point this out.  Oh, and props to Ameo for taking some cool photos – I need to find out what his(her) setup is.

Update: It looks like Ameo is having some trouble so I am going to help out and mirror the files here.  Check them out after the break.

Continue reading “» iPhone 3G unboxing pictures, now with more indecisiveness”

» I [heart] Fail Whale

If you aren’t on Twitter or are living under a rock (or both, perhaps) you may not know my latest love interest.  In any case Fail Whale is Twitter’s faithful representative bringing joy to the hearts of those in pain when there are too many tweets.

If you want more information or just to be part of something special go visit the Fail Whale fan club site here or peep the banner to the right.  Also don’t forget to give some love to Yiying Lu, the famed creator of the comforting whale; you can peep the original illustration along with some other great work here.

» Now with more validation!

In case you haven’t been following along during this journey of mine I’ll go ahead and spill it out for you – I have no idea what I’m doing with this whole “blog” thing.  However, I am learning a LOT…  It seems everytime I make a change something breaks and I get to learn how to fix it.

Well, today, I finally passed another milestone; one which I have been tinkering with for quite some time.  My site is now valid W3C XHTML (transitional) and CSS!!  This is something I really wanted and because of my limited knowledge has been slow in coming.  I’m very glad that I have reached this milestone as interoperability is extremely important to me.  I don’t want to learn/use code that only works correctly in some environments, instead I want to learn things the right way!

If you want to run the test yourself and celebrate along with me you can scroll to the bottom of my page.  I have placed links to both the XHTML and CSS validation tests in the footer as a trophy to remind myself of this amazing (to me at least) feat!

» Automagically resize your windows

Automatically resizing your application windows based on resolution is a topic that I find pretty interesting and has been covered by two of my favorite sites here and here.  The script was originally written by Jeff Kelley on his blog.  After playing with the script for a few hours I finally got something together that I like.  I wanted to post my version of the script and a few notes for people to review if they want to tweak the original script.

I will start by saying I like my windows to be as small as possible so I can have as many open apps visible at a time; but here are a few things I ran into…

1) The quotation marks are not copying correctly from the site into script editor so you will have to replace them manually prior to compiling.

2) The format of the bounds for the windows is also useful to know. First notice that the very top of the desktop (just below the menu bar) is y=0 and the very left the desktop is x=0. The window bounds follow this format (dist x left, dist y top, dist x right, dist y bottom). Distance from x(y)=0 to [window side]. If that doesn’t make sense I’ll try to make a visual diagram.

3) You can quickly find the values of distances using CMD+SHIFT+3 and looking at the coordinates as you drag the selector around the screen.

4) Because of how I like my windows I found it easier to do all of the resizing within two if-statements. ie. If Width = 1920 size the windows this way, If Width = 1440 size the windows that way.

View the full entry to see my script.

Continue reading “» Automagically resize your windows”

» Green Plug, a really good idea

Green Plug featured here and here is a new technology from the up and coming startup of the same name.  It’s mantra “One Plug. One Planet.” is indicative of the eco-friendliness on which the company is found.  Green Plug wants to change the way consumers and manufacturers think about AC adapters, batteries, and basically things that plug into the wall.  

The general idea is that all devices will use a truly universal AC adapter and that this will cut down on waste.  Green Plug takes this idea further by making their plugs “smart”.  Essentially, a Green Plug would feature an LCD status display and when paired with a compatible device provide information about the charge status.  Further, because the Green Plug-enabled device would also be “smart” the Green Plug would cut the flow of power when the battery was fully charged and thus resulting in a reduction of power usage.

Currently there is a movement to standardize mini-USB as a power plug for many devices.  An unfortunate limitation of this tech is that USB simply cannot handle the load required by most devices larger than a cell phone.  Green Plug-enabled devices would be able to notify the Green Plug of its specific power requirements and in this way it is more intelligent and more capable than the USB-powered counterparts.

Green Plug is versatile and wants to be integrated into hubs, shops, offices and even homes.  Aftermarket AC adapter providers like Targus could use Green Plug to create hubs capable of powering multiple devices at a time.  The LCD read-out would provide status information for each connected device.  Retail locations and offices could implement Green Plug to save energy and allow anyone with a Green Plug device to sip some juice from the power grid.

A big benefit that seems to be over-looked is integration with Smart Grid technology.  Smart Grid is an idea being implemented by many major power companies to provide transparency to end-users regarding real-time pricing and usage of power.  In other words, Smart Grid aims to have a household’s appliances use more power when the price of electricity is low and use less power when the price of electricity is high.  Green Plug is smart too and could be integrated with Smart Grid to reduce load based on the information provided by the user’s power company.  Some devices can be charged less quickly by limiting the amount of power that is provided.  In this way it would be possible to charge a device and specify whether charging speed or energy savings are a priority.

While Green Plug has a lot to over come it has the right idea with its focus on energy savings and universal access for the end-user.  Green Plug’s Earth first principles have come at a great time when energy prices are constantly on the rise.

» I’m a consumer whore.

And how!

But in all seriousness, I am.  Last November I bought myself an HD DVD player using my birthday money.  I was convinced that HD DVD would win the format war.  Because, I told myself, WB and Paramount are firmly situated in the red camp. AND! “HD DVD” is such a consumer friendly name that even Joe Wal-Mart would understand the concept.

Well, as it turns out, HD DVD did not win the format war.  In fact, Sony bought the format war with its late-to-the-game Playstation 3.  So bitter was I as I watched HD DVD players plummet in price along with their high definition disc buddies.  I cringed at the thought of having to admit to my home theater that a Blu-ray player would be joining the stack soon.  I assured my many components that a Sony would never be brought home.

Boy was I wrong.  Thanks to a failing economy the government tried to buy me off in an effort to assure me that “we’re not in a recession”.  Whatever – free money to spend on whatever I want.  I faithfully drove to Best Buy on that fateful Saturday with my stimulus money in hand.  After all, I had to spend it; if I didn’t, the terrorists would win!

As it turns out I quickly found myself in the Blu-ray section of the store.  There were so many options to choose, oh but I had done research.  Never content to simply ask a sales person what the best choice for me would be I have to prove I’m the smartest person ever and must know everything there is to know before making a final decision.  You see, I have an addiction – the only prescription is owning the best.  It’s a sick sad life, but as I mentioned earlier, I’m a consumer whore, so you knew this coming in.

It didn’t take long to realize Best Buy didn’t have the model I wanted and a quick search on the internet revealed to me that not only was it not yet released, it was about $200 outside my price range.  My heart sank.  The misses tried to console my broken spirit but I was a lump.

However, our story doesn’t end here!  I happened to run into a dear friend and trusted advisor.  We spoke on the matter and his recommendation shocked and appalled me.  He said he had Playstation 3 and that I should get one.  He said it was a great player and even greater value!  I was incredibly surprised by his recommendation – how could I even consider purchasing something that was a) Sony and b) not a stand-alone Blu-ray player!?

Well he was right.  I bought one and I haven’t regretted it yet.  Speaking from a purely un-objective standpoint, it’s pretty cool I have to admit.  The picture and sound quality is far and away fantastic – I was/am very surprised.  All in all, I’m very satisfied with my purchase.

What did I learn from this whole experience?  Well, first of all, I learned that I can’t stick to my “feelings” when it comes to purchasing the latest and greatest tech gear.  I need to go with the facts and not care about any loyalties or biases I may have.  For a long time I didn’t even consider the PS3 because it was a Sony product – and I think that was just lame.  I could have saved myself a lot of time if I had just opened myself up to whatever possibilities presented themselves rather than letting other things get in the way.  The other thing I learned is that I’m a consumer whore.  I don’t think that needs any explanation because it’s just a fact.  I am – deal with it.

UPDATE3000:  PS3 as Blu-ray player = teh rocks!