Adjust first names with AppleScript in an Address Book Group

Jeroen | May 2, 2008 1:47 | 1:47

At my company the sysadmins provide a little service when putting all phone numbers of colleagues on my cell phone. Every colleague is prefixed with a dot. My car’s carkit though lists all numbers grouped by alphabet. So this leads to like a couple hundred entries grouped under a single dot. Fortunatly I can sync my phone to my Apple’s Address Book. When it’s in there, the following little AppleScript allows me to change all first names starting with a dot to something without a dot.

First I transfer all dot-prefixed entries to a special group, then this script runs the people in that group through a little check and adjustment when needed.

(The syntax of AppleScript is a real pain.)


on lstripString(theText, trimString)
	set x to count trimString
	try
		repeat while theText begins with the trimString
			set theText to characters (x + 1) thru -1 of theText as text
		end repeat
	on error
		return ""
	end try
	return theText
end lstripString

tell application "Address Book"
	set infoSupporters to people of group "InfoSupport"
	repeat with p in infoSupporters
		if first name of p starts with "." then
			set new_first_name to my lstripString(first name of p, ".")
			set first name of p to new_first_name
		end if
	end repeat

	display dialog "Done!"
end tell

I keep forgetting that -u does an uninstall of old macport versions

Jeroen | February 18, 2008 0:37 | 0:37

macports-logo-top.pngAccording to the MacPorts port command man page the option -u: “uninstall non-active ports when upgrading and uninstalling”.

Just running port upgrade all the time litters your systems with lots and lots op old archived versions of installed ports.

To correct this whole mess you could run “sudo port -u uninstall”. This should uinstall any archived versions you might have. You might need to add a -f to that to make it work: “sudo port -uf uninstall”.

You might have some trouble when you force a removal like this when one of your installed ports is linked against an older version of a library. This can be fixed by replaying some steps on this page.

Basically this post is a reminder for myself. But just maybe someone might find this useful too.

TrueCrypt released for MacOSX, using MacFuse

Jeroen | February 6, 2008 23:43 | 23:43

Yesterday TrueCrypt version 5.0 has been released. Nothing special you might say, but then again, you might not be running Mac OSX. TrueCrypt has been released for the Mac as well. The cool thing about it is that it uses MacFuse.

Download TrueCrypt here.
You will find several options suitable for your system.

MacFuse is a kernel extension for the OSX operating system allowing mounting of file systems in user space. With MacFuse a user can mount a file system dynamically without needing super user privileges. MacFuse is based on the original Fuse kernel extension for Linux based operating systems. With MacFuse/Fuse you can do cool things like an mounting a remote file system over SSH, a screenshot file system dynamically generating screen shots of all active windows on your desktop or just about any other piece of data that can be mashed in to a hierarchical layout or read/write NTFS file systems. You probably think this is boring. But the thing is, it’s all dynamic. Without MacFuse I guess implementing TrueCrypt for Mac would have been a whole lot harder.

With the release of the latest TrueCrypt using a secure portable drive is finally a decent option for me. Sure OS X already has the concept of secure DMG files. But those are kinda Mac only. And I have to be able to carry stuff between my Mac and several Windows machines.

One word of caution though, remember that you do need to make some form of back-up of all your encrypted data. Back-up the individual files or the entire encrypted disk image. Because if only one bit falls over in your encrypted disk, the entire disk will be corrupted.

Apple Mail just really keeled over on me… I whacked reply to much…

Jeroen | June 19, 2007 20:12 | 20:12

I was trying to forward a message. One with loads and loads of replies. Really in the order of dozens of replies on replies.

Aaaaanyway… I thought, what the heck I'll give Apple Mail some time.

And there Apple Mail was munching away… ..on my internal memory that is!! After about 10 minutes or so Apple Dumped on me. Turns out the Kernel identified Apple Mail as a run-away procces.

Luckily, I had taken a snapshot with the Activity Monitor…
Now look at that screwed call stack. Something was definatly going up the recursion tree.

Analysis of sampling pid 700 every 10.000000 milliseconds
Call graph:
300 Thread_0f07
300 0×94d19
300 0×94df2
300 NSApplicationMain
300 -[NSApplication run]
300 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]
300 _DPSNextEvent
300 BlockUntilNextEventMatchingListInMode
300 ReceiveNextEventCommon
300 RunCurrentEventLoopInMode
300 CFRunLoopRunInMode
300 CFRunLoopRunSpecific
300 __CFMachPortPerform
300 __NSFireMachPort
300 -[MainThread handlePortMessage:]
300 _invokeInvocationRequest
300 -[NSInvocation invoke]
300 objc_msgSendv
300 0×67fbd
300 0×6a506
300 0×6a5a5
300 KWQKHTMLPart::setSelectionFromNone()
300 khtml::Selection::Selection[in-charge](DOM::Position const&, khtml::EAffinity)
300 khtml::Selection::validate(khtml::ETextGranularity)
300 KHTMLView::layout()
300 khtml::RenderCanvas::layout()
300 khtml::RenderBlock::layout()
300 khtml::RenderBlock::layoutBlock(bool)
300 khtml::RenderBlock::layoutBlockChildren(bool)
300 khtml::RenderBlock::layout()
300 khtml::RenderBlock::layoutBlock(bool)
300 khtml::RenderBlock::layoutBlockChildren(bool)
300 khtml::RenderBlock::layout()
300 khtml::RenderBlock::layoutBlock(bool)
300 khtml::RenderBlock::layoutBlockChildren(bool)
300 khtml::RenderBlock::layout()
300 khtml::RenderBlock::layoutBlock(bool)
300 khtml::RenderBlock::layoutBlockChildren(bool)
300 khtml::RenderBlock::layout()
300 khtml::RenderBlock::layoutBlock(bool)
300 khtml::RenderBlock::layoutBlockChildren(bool)
300 khtml::RenderBlock::layout()
etc, etc, etc… (You get the idea here?)

How I resolved this you say? Well, the weird thing was that Apple Mail was able to start and just show me the offending mail. Only when I tried forwarding OR replying things got ugly. I went into the Mail folder in my Library to VI my way out of it. As in locate the emlx file of that particular mail and "dd" the crap out of it to cut it down to size a bit. Then everything worked again in Apple Mail. All things went sunny again. (I do have the original message lurking on my pop box. So if any OG Apple engineer wants to look at it. Pleeeeeeease do contact me.

Darwinports is freaking me out!!

Jeroen | September 28, 2006 21:57 | 21:57

Ruby on Rails project logoMan, am I having hard times with Rails and DarwinPorts MacPorts or what? The strangest things keep happening. My Rails install broke down again. Imagine my frustration. I’ve been messing around with it for a few days now. And trust me, nothing wrong with rails. This time it was an incomming update on a support library called gettext. Argh!! On itself nothing wrong with updates, and that stuff breaks because of it, fine. But not all in one week please.

In hindsight the fix was real simple.

  • sudo port uninstall [insert anything starting with rb-]
  • sudo port install rb-rails

Oh and another one if you would want to use rb-sqlite3 on Rails. Install swig before installing the sqlite adapter. And don’t forget, in your database.yml: adapter: sqlite3 Yes, with a three that is.

Just a sidenote: I officially fell in love with TextMate. This editor is soooo cool. Thank you very much MacroMates.

Quartz 2D Graphics

Jeroen | September 9, 2006 18:57 | 18:57

Quartz 2D Graphics for Mac OS X(R) DevelopersI haven’t finished the book yet, I’m about half way through. But so-far it’s a great book about an excellent part of Mac OSX.

The book details how you should use Quartz 2D and Core Image. Quartz 2D is a central piece in the graphics development on Mac OSX. The thing with Quartz 2D is the fact that it is resolution and color independent. And this book really hammers it down. The interesting thing to me is the fact that Graphics 2D in Java is also resolution and color independent. This resolution and color independence makes it possible to program in a device independent manner. The “device” can be the screen, a memory bitmap, a PDF file/memory structure, a printer or anything else which is capable of displaying or producing graphics. The end result of this is that you only have to write your drawing code once without any device specific intricacies. There are a few things to keep in mind in a few exceptional cases, but that’s usually not a problem at all.

The book doesn’t seem to contain a lot of code. Most of the time it shows a few snippets to get a point across. But every listing comes with a number which references a file on the accompanying compact disk. Excellent stuff, you see something interesting, you want to fiddle with it in an editor anyway. So why waste precious page space? I personally hate it when books are half code, half actual text. Quartz 2D graphics on the other hand strikes just the right balance to me.

This books also goes into Core Image. Core Image is a framework on OSX which allows programming of the systems graphics card. If the graphics card does not support such actions Core Image provides a soft alternative, which is a lot slower offcourse.

Note to self: Never run “sudo port upgrade all” again

Jeroen | September 7, 2006 19:03 | 19:03

“Ghee whiz… That was taking mighty long” I thought, “Why has my PowerBook been compiling and compiling for over 30 hours now?”

Then I remembered the command I entered to upgrade all installed MacPorts. I should have used installed instead of all. *Sigh!* I’ve just deleted my entire MacPorts install because I think it’s easier for me to actually just reinstall the few MacPorts I use.

MacPorts is a toolset for Mac OSX which allows you to get loads of unix tools ready and ported for the Mac OSX operating system. It’s a bit geeky, but it sure beats having to install everything by hand and hope you didn’t miss a mac specific patch.

DTrace in OS-X

Jeroen | August 15, 2006 13:26 | 13:26

While I’m not feeling very good today, I have a headache again, one can only stay in bed for so long. So while browsing around a bit (http://www.opensolaris.org/os/ to be exact).

I stumbled upon some very positive news from the Apple Word Wide Developers Conference (WWDC). According to ZD-NET Australia the next release of Apple OS-X, Leopard, will support DTrance. It also gets an Apple work-over, so it will probably look and feel good too. Take a look at the bottom of Apple’s Leopard preview page. Apple will include a tool called XRay which will leverage DTrace to provide its functionality. Knowing Apple this will probably mean that the original tool will be included as well.

For those who are wondering what DTrace is. Well, it’s a comprehensive dynamic tracing framework. DTrace provides a powerful infrastructure to permit administrators, developers, and service personnel to concisely answer arbitrary questions about the behaviour of the operating system and user programs.

“What?” you might say… well it comes down to this:
For Users:

  • dynamically enable and manage thousands of probes
  • dynamically associate predicates and actions with probes
  • dynamically manage trace buffers and probe overhead
  • examine trace data from a live system or from a system crash dump

For Developers:

  • implement new trace data providers that plug into DTrace
  • implement trace data consumers that provide data display
  • implement tools that configure DTrace probes

(Source: http://www.opensolaris.org/os/community/dtrace/, you can find a more detailed description of DTrace there as well.)

Let’s just say, seeing is believing. Once you see DTrace in action, you’re hooked.

New project assignment, something with Python

Jeroen | July 26, 2006 23:50 | 23:50

Python logo I’ll be taking over a few tasks while a colleague of mine is taking some well deserved R&R. The thing is, I’ve heard it involves Python. *sweet* ;)

That does mean I’ll be scrapping my Ruby experimentation, because I have to brush up my Python skills a bit. It’s been a while since I’ve done any serious Python coding.

If you’re looking into Python too, start here. Oh and, MacOSX 10.4 comes with Python 2.3.5 pre-installed.

First steps with Ruby on Rails

Jeroen | July 22, 2006 2:57 | 2:57

Ruby on Rails project logoAs any self respecting software developer I jumped on the Rails bandwagon too. It will probably not be something I will be using a lot in the near future, but staying informed never hurts.

So of I went to a local bookstore to do some browsing and this resulted in purchasing a book called Agile Web Development with Rails: A Pragmatic Guide (Pragmatic Programmers) by Thomas and Hansson. The upper left corner says “The Pragmatic Programmers”, which resulted in me feeling good about buying this book, since I loved “The Pragmatic Programmer: From Journeyman to Master“.

Agile Web Development with Rails: A Pragmatic Guide (Pragmatic Programmers)The Rails book is very well written. I have not gone through it yet from cover to cover. Right now it’s the book I’m reading at home when I require some privacy. ;) I find a toilet a place of serenity and quiet contemplation. Or an excellent place to focus one’s complete attention to the contents of a book.

I am running a PowerBook G4 here with OSX. And as the book stated, OSX comes with Ruby pre-installed but requires some tinkering. I opted for the latest Ruby version. So I went with a OpenDarwin Ruby/RubyGems/Rails install. No problem in that area.

The Pragmatic Programmer: From Journeyman to MasterNext up was a database. The Rails book says MySQL is good. So I go with that, although I think an in process DB like SQLite would do just as well for me. Let’s just say it’s been a while since I did a MySQL install. Although it isn’t really necessary as far as I am aware, but I couldn’t get network connectivity to work with MySQL 5. Turned out to be really stupid. Of-course I need to give a user the right on the MySQL instance to actually connect through the network.

Once I got MySQL sorted the fun could begin. Right now I just about finished building the web-shop cart. See, the book uses a simple e-shop as an example. Through the course of about 8 chapters you can build a basic shopping experience. I like this tutorial approach when taking my first steps with a new framework.

MySQL logoIn the end I guess I will get a pretty decent overview of Rails. And while I do get the feeling Rails can be a huge timesaver, it does still feel awkward to me that you should do it the Rails way or preferably not with Rails at all. The whole programming by sensible default is still a bit jarring. I guess because I am more used to rocket science style over-engineered Java systems. Not the most effective use of Java in my opinion. But hey, I’m no software architect yet, so why should anyone listen to my opinion. ;) Also I can’t quite get that Ruby syntax in my fingers yet. Perhaps I should look into buying the pickaxe book too.

I am very curious about where Ruby on Rails will be in a few years. Although many people claim that it’s not ready for prime-time yet, that it’s still a technology too new for “enterprise implementations”. (That’s one term for your BS-bingo list.) I think that Ruby on Rails may actually be further along and actually quite capable and ready for prime-time. I guess time will tell. It is an interesting framework and takes some refreshing approaches, so even when you are not going to use it this or next year do take a peak at it. Most likely some of the concepts of Ruby on Rails will actually be useful for your regular dayjob.

Oh and about the book, yes it is an excellent read on Ruby on Rails if you like a tutorial style read.