» Steve Jobs, 1955 – 2011

Here’s to the crazy ones, the misfits, the rebels, the troublemakers, the round pegs in the square holes… the ones who see things differently — they’re not fond of rules… You can quote them, disagree with them, glorify or vilify them, but the only thing you can’t do is ignore them because they change things… they push the human race forward, and while some may see them as the crazy ones, we see genius, because the ones who are crazy enough to think that they can change the world, are the ones who do.

Continue reading “» Steve Jobs, 1955 – 2011”

» Year in review: 2008

2008 was a pretty busy year — a lot of things happened that made it quite a ride. I thought I would take a moment to go over some of the more notable events that have occurred in the last 366 days.

UPDATE: It took me almost three months to realize that last year was a leap year. My apologies to 02/29!

Continue reading “» Year in review: 2008”

» 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"
activate
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"
activate
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.

» 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!”

» Hosts file issue

When I was first setting up wordpress on my Mac mini (which as you’ll recall is on my dedicated DSL line) I ran into a problem using the dynamic DNS name I had set-up.  With wordpress when I wanted to visit the site from inside my LAN it would automatically re-direct to the location of the set determined in settings.  This caused a problem because that location pointed to my dynamic DNS which in turn pointed to my WAN IP address and well as you can imagine wordpress go boom.

My temporary workaround during installation and initial set-up was to ignore this entirely as I was only working on the site from home.  This was short-lived as I realized I had a life and wanted to work on the site when not sitting in my home office.  Oh, yeah, and I guess I wanted the rest of the internet to have access as well – I suppose that was a factor as well.

What I ended up doing was using two hosts files, one that had the following line:

10.0.1.195     aroncares.dnsdojo.com

and another that had that same line commented out:

#10.0.1.195     aroncares.dnsdojo.com

To quickly switch back and forth I used two shell scripts, set to open by default using Terminal, that copied a “home.hosts” or “away.hosts” file on top of the hosts file.  (FYI, in Leopard, this file is located at /etc/hosts)  This worked great and was easy enough, but it didn’t have the panache that I was looking for in this situation.

The final solution that I worked out is really everything that I want (unless you include my desire to have this site hosted elsewhere) given the situation.  What I ended up doing was taking a crash course on AppleScript and writing an application that would simply ask me whether I’m home or away and act accordingly.  Interestingly I was able to give the shell script root privileges which is required to make changes to the hosts file.  For anyone that is interested I have pasted the syntax of the script after the jump.

Continue reading “» Hosts file issue”

» Day 2 – some small fixes and more info

Utilizing my EXTREMELY limited (non-existent) knowledge of PHP I managed to create a Page.php template separate from the Articles.php template. This resolved one of my issues with this theme – specifically, since there was not previously a Pages.php template my About and Contacts pages were simply using the posts template – not attractive.

I also dugg into the CSS a little bit and changed a few colors around to suit my liking. While I was doing that I discovered some sidebar stuff that could (possibly) be tweaked to make it (and my search widget) less ugly. I know a TINY bit more CSS than I do PHP so I stumbled my way through rather than commenting-out random lines and crossing my fingers.

Here are some details about the site that might interest anyone who is curious… Since I am not financially capable (broke) I cannot currently afford paying someone else to host the site. It’s another monthly bill and I would rather buy a house. That being said I am hosting the site on my Mac mini using my business DSL line. Until I get a domain set up I’m using the free and awesome dynamic DNS service. It is particularly nice because for OS X there is a dashboard widget that updates dynDNS of your IP address.

I know you’re probably thinking “oh crap, if three or more people are on this site it’s going to crash” – well, you’re probably right. Actually, I have more faith in Apache, MySQL, and PHP on my Mac mini than I do my ISP’s ability to handle the bandwidth.

I consider this quite a feat because of two points 1) I know almost nothing about most web technologies – the fact is I’m a n00b. But I’m proud to admit it and determined to change it. I think that’s important. The reason this is a feat is because it was incredibly easy to set up using OS X.

The UNIX underpinnings in 10.5 make my Mac mini a fairly robust server for a fraction of the cost of an Xserve. Enabling Apache required me to simply check a box – that’s it. Granted there were a few other steps involved in enabling PHP and installing MySQL; but let’s be realistic, one is going to have to dirty one’s hands at some point.

Please pardon me if I’m sounding too much like a “fanboy”. In all honesty, I would install whichever OS made it the easiest – I’m not afraid of using a Linux distro. or installing Windows on a Mac. The fact is that OS X made it the easiest to accomplish the goals I wanted to accomplish.