My Journey to Macintosh

Entries from April 2006

Automating iTerm

April 12, 2006 · 7 Comments

So I wrote my first AppleScript this evening and I guess (if you stretch the definition a bit) this could even be classed as my first piece of Mac OS specific development!

I am doing some Ruby on Rails development at the moment and every time I work on it I have to set up the same environment, same steps time after time:

  • Launch iTerm
  • Change into my rails project folder
  • Launch TextMate for the project folder
  • Launch another iTerm session
  • Change the new session into my rails project folder
  • Launch the rails server

Ripe for automation but not something you could achieve in a shell script (as far as I remember from my 12 year old knowledge of shell scripting) due to the interaction with iTerm windows and sessions, so a perfect chance to get to grips with whatever the hell AppleScript is all about.

First, I looked at Automator because I figured that had something to do with AppleScript but it turns out that you can run AppleScript from within it but that itself it had no hooks to either Terminal or iTerm so I moved on.

I found a decent tutorial at the Apple developer site which used XCode and AppleScript Studio and so I followed that through but that was for creating a fully fledged Cocoa application with AppleScript (which I didn’t even know you could do!) but that isn’t what I wanted, I just want a simple script to automate a couple of iTerm windows. It’s cool that XCode is free and included with OS X but wow, it is a full serving of confusing when you open it for the first time, isn’t it.

Anyway, I ended up developing my script with TextMate editing a .scpt file and then executing it via osascript. Unfortunately most of the AppleScript documentation at the iTerm site is incorrect or out of date because it does not work but I managed to find another example and built my script from that (I wont go into the actual development of the script, suffice to say it does everything in the bulleted list above).

So then I had to execute the script, so I went back to Automator and put it together in a little workflow along with an action that let me pick a folder before sending it as an argument to my AppleScript. This was really easy apart from one gotcha with Finder paths using : characters to separate folders in a path instead of slashes. So I had to convert them with:

set path to POSIX path of (item 1 of input as alias)

I saved the workflow and set it to execute with Automator Launcher instead of the editor and I now have a very neat little script that asks me for a folder and then sets up my Rails environment just like I want it. I have uploaded the final workflow here.

AppleScript looks to be really useful but I have to say I hate the natural language syntax :) I don’t feel constrained by the language but of course I still am because it isnt actually a natural language processor, just a syntax that resembles natural language. Maybe its the developer in me but I would find it easier to learn a computer language that looks like a computer language :)

Technorati Tags: , , , , ,

Categories: Software · The Journey

It’s the little things…

April 12, 2006 · 27 Comments

So this post isn’t going to focus on huge changes, sometimes its the little things that count. Specifically, the way that Mac OS handles files and folders that are in-use.

This can be a area of pain for Windows users, who hasn’t seen the error message below and despaired at how to find the file that is in use by either guessing/checking every open command prompt or using a tool like Handle or FileMon.

Access Denied

Note: Much of the pain caused by this message could be avoided if the in-use file/folder information was included on this message. I probably wouldn’t be writing this post if it was.

To say Mac OS X handles this in a better way would be an understatement of colossal magnitude (Ok, Ok, maybe that is overstating it but I really hated this under Windows :).

Take this situation:

Rename1

I have a folder, with a file in it. The folder is open in a finder window and a terminal window, the file is also open in preview. Recipe for disaster, right? :)

Rename2

Rename the file and the file updates in the finder, so far so good but Windows also does this. Click on the preview window though and the title bar updates… kinda neat but not earth shattering :)

Rename3

Now rename the folder and everything just works again. The open Finder window just updates, the preview updates. Very neat but still, we haven’t really improved on Windows yet. In Windows the folder would have closed instead of updating, but it’s a small victory :)

It is the next step where it gets interesting though:

Rename4

I removed the folder from the finder window and two things happened:

  • There was no 10 second pause, followed by the error.
  • The terminal window actually switched to follow the folder into the trash.

I could have also renamed the folder with the Finder window and the terminal window would just have updated next time I used it. The whole process “just works™”, it is so elegant it hurts.

Now this isn’t going to be a massive pain when all three windows are positioned right next to each other and visible like they are in this example, but how often does that happen in real life :) The terminal or command prompt is usually 16 windows deep or some rogue app has left open file handles to something and you end up in a reboot as the quickest way to fix it. It just wouldn’t happen here.

Like I said, it’s the small things :)

But… It isn’t completely rosy, I have a criticism that I found while writing this up, and while it is only a small point it is quite significant. Files removed with command line “rm” don’t get moved to the Trash. This is quite inconsistent and I am guilty of relying on the Trash/Recycle Bin too much sometimes :)

Update: I always thought that Windows honoured the Recycle Bin from command prompt but I just tested it and it doesn’t. Who knew!

Technorati Tags: , , , ,

Categories: Software · The Journey

Proteus Dissapointment

April 10, 2006 · 17 Comments

So many people have recommended Proteus as an alternative IM to Adium in my comments here that I thought I must be missing something special. Well as true as that may be, for now it seems it will remain that way :)

I installed it tonight and it simply doesn’t load :) I dragged it to my Applications folder and launched it. The icon appears, bounces a few times and then disappears. No Error message, no clues at all.

When I try and search on their forum for solutions, I get the message “Error: Unable to search for posts.” but from the front page I don’t see anyone else who is having this issue. It is not a universal binary, but that shouldn’t matter.

Not a great start :) Does anyone have it working successfully on a MacBook Pro?

Technorati Tags: , , , , ,

Categories: The Journey

… and the prize for most creative use of hardware goes to …

April 9, 2006 · 8 Comments

iAlertU, but the video says it best…

Direct link, because the embedded video is being flakey.

This is not a serious security device, and never will be for as long as the thief is still able to hold down the power button for a few seconds. But it is a nice deterrent, and there is a real market for something between something like the Kensington locks (that in my experience often get bought and rarely get used) and leaving a completely unsecured laptop.

I just finished trying this out and it worked, it is Intel only (shock!) at the moment but apparently PPC PowerBook and iBook versions are in the works.

Technorati Tags: , , , ,

Categories: The Journey

Witch

April 9, 2006 · 17 Comments

The power of a blog that people actually read is amazing :) Within 10 minutes of that last post, I have a solution that solves pretty much all of the issues I was having with Command+Tab.

Witch (http://www.petermaurer.de/nasi.php?section=witch) looks to be exactly what I was looking for in terms of switching between windows rather than applications. It allows me to cycle through windows instead of applications and can order the items in terms of most recently used window instead of per-application (it’s default). It doesn’t show non visible windows like Quicksilver and Adium in the dock and it can zoom and minimise right from the Alt+Tab screen.

The only thing I can’t seem to do is make it replace Command+Tab. In the keyboard shortcuts system preferences panel, I can see the shortcut for cycle between windows Command+` but I can’t see one for cycle between applications, and when setting the shortcut for Witch when I try and press Command+Tab, of course it switches applications rather than setting the shortcut.

Thanks very much to Ton who left this recommendation in my comments.

Update:
There seems to be a small bug with Witch when you have it configured to cycle through windows in window use order. This works fine between windows in different applications but switching back and forth between the topmost two windows in the same application does not seem to select the correct window. I will e-mail the author and see if he can reproduce it.

Technorati Tags: , , ,

Categories: The Journey