hasseg.org

Mac

Faux Pas: Static Error Detection for Xcode Projects

Filed under iOS, Mac, Programming

Faux Pas icon I have been working on an app called Faux Pas for a long time now. It's a static error detection tool for Xcode projects: you point this app to your project, and it'll work through it, trying to find common errors or departures from best practices.

It's been in a long private beta, and now it's time to release it to a wider audience. Find more information from the introductory blog post over at the app's website.

The Compiler is Your Friend

Filed under Featured, iOS, Mac, Programming, Talks

Which compiler warnings should I enable for my iOS/Mac app project? How do I enable warnings that Xcode doesn't have a checkbox for? How do I disable warnings (either completely, for specific files, or in specific sections of code?) Where do I go to find out what warnings are available? How do I enable warnings for my own code, but disable them for third-party code that I compile into my bundle? What about warnings that are triggered in third-party headers?

I did a talk on compiler warnings at the HelsinkiOS/CocoaHeads April 2013 meetup that answers all of the above questions. The slides are available at Speaker Deck, and embedded in this post below.

Handling NSStrings Like a Boss

Filed under Featured, iOS, Mac, Programming, Talks

Strings are arguably the most common data structures used by practicing programmers. They're easy to conceptualize as “sequences of characters,” but it's important to note the leakiness of this abstraction, and to know how (and when) to consider the details of how what we think of as “characters” are represented in modern software.

I did a talk on this topic at the HelsinkiOS/CocoaHeads February 2013 meetup — obviously from the point of view of Apple's platform APIs. The slides are available at Speaker Deck, and embedded in this post below.

iOS & OS X Localization Practicum

Filed under Featured, iOS, Mac, Programming, Talks

I did a talk on the localization of iOS and OS X projects at the HelsinkiOS February 2012 meetup. The slides are available at Speaker Deck, and embedded in this post below.

Getting Events/Tasks From the OS X Calendar Store in a Custom Format like XML, CSV or LaTeX

Filed under Mac, Programming, Scripts

Over the past couple of years I've gotten a few emails from users of icalBuddy who would like to somehow automate the task of generating CSV, XML/HTML or LaTeX output from the items in their calendar. Unfortunately icalBuddy isn't set up to provide any kind of arbitrary output format (and I didn't want to re-architect it to do that) but a while ago I finally had the time and motivation to figure out a small solution for this: a Python helper class for writing scripts that produce whatever type of output your heart desires.

How to Display Events or Tasks on Your Desktop With icalBuddy

Filed under Featured, Mac, Miscallaneous

icalBuddy, GeekTool, NerdTool icons I don't really have any statistics about this but I'm quite sure that an overwhelming majority of the users of my icalBuddy program are using it to display calendar data on their desktop via GeekTool. Several tutorials on how to get this done have been written by different people, mainly for relatively non-technical users, which I think is great. The problem seems to be that many people don't know how to configure icalBuddy to give them the kind of output they'd like and end up copy-pasting the commands from these blogs (some of these blog posts also contain outdated information about a bunch of things). Hopefully this short tutorial (and the usage examples page) will offer an easy way to make a more informed decision about how to get this done.

Prevent iTunes websites from opening the iTunes app using GlimmerBlocker

Filed under Mac, Miscallaneous, Scripts

A few minutes ago I clicked on an iTunes store link on a website and had to again completely lose it because of the iTunes app popping up without me asking it to. This is a common annoyance that people have found a bunch of different ways to combat, ranging from messing with the system's (or the browser's) mapping of URL protocol handlers to rewriting parts of web pages via a browser plugin (e.g. GreaseMonkey) or a localhost web proxy (e.g. GlimmerBlocker).

Trash files from the OS X command line

Filed under Featured, Mac, Programming

trash picture I spend a lot of time in the Terminal on my computer -- a lot of things are just better done with a command-line interface than in the GUI. When removing files via the command-line people usually just, well, remove them (with the rm command), but this means that they'll be eschewing the Trash, one of the user-friendliest things (even relatively) modern operating systems have had to offer for a long time.

Print AppleScript files with color-coding in the Terminal

Filed under Mac, Programming, Scripts

asprint image Even though I curse and hate its syntax, I have to admit that AppleScript certainly provides one of the nicest things OS X has to offer in comparison to other operating systems: almost-ubiquitous scripting of GUI applications (one could argue that this is not due to the AppleScript language itself, but the Open Scripting Architecture which AppleScript is simply a language for, but that's just semantics). Recently I've had to work with AppleScript files a bit more than usual while implementing Tagger's front app scripts feature, and I noticed that I often wanted to print out the contents of (compiled) AppleScript files in the Terminal. The built-in command osadecompile does just that: it reads in the AppleScript file, decompiles it, formats the code and nicely prints it out. I'm used to seeing my code with syntax highlighting, though, so I decided to write a small program that works similarly to osadecompile but uses ANSI escape sequences to format the output.

My Custom GeekTool 2 Build with Support for ANSI Colors, UTF-8 and Different Writing Directions

Filed under Mac

GeekTool-hasseg-logos A year ago I released version 1.0.8 of my icalBuddy command-line application that I initially wrote as a way to get nicely formatted lists of my events and tasks from the OS X calendar store on top of my desktop background picture using GeekTool. This particular version was notable in my mind because it introduced initial support for formatting the output via ANSI escape sequences. The initial formatting was static (that is, you couldn't change it) and very simple (it only made the titles bold), but since then I've implemented all kinds of different customization options that can be used to specify how the output should be colored and otherwise formatted. The only problem was that GeekTool didn't support ANSI escape sequences, which meant that instead of the nicely formatted output I wanted GeekTool would display a bunch of gibberish if I used the -f icalBuddy argument.

Update (Sep 6, 09): Recompiled the preference pane as 32/64-bit binary with support for garbage collection so that it would not force System Preferences to restart on Snow Leopard.

Quick Look Plugin/Generator for Image Folders

Filed under Mac, Programming

plugin One of the things that I've always thought Windows XP did better than OS X is how it displays the thumbnails of contained images on the icons of folders that have image files inside them. I always felt this to be quite useful, but couldn't think of any reasonable way to implement it on the Mac before OS X Leopard came along with its Quick Look plug-in architecture.

Opening a Bunch of Stuff at Once on Your Mac

Filed under Mac

LaunchList application icon Every day when I come to work, I have a bunch of applications, files and web pages I need to open in order to get started. These are almost always the same, though with a little variation (for example, sometimes if I need to do something that requires a lot of concentration I might want to leave Adium, my instant messenger app, closed.) Now, let's face it -- opening a bunch of applications, files and web pages is not a lot of work: you just clickety-click on several icons on your Dock or Desktop, then switch to your web browser (after it's loaded, of course) and click on some bookmarks in your bookmark bar or menu. But the problem is that I'm lazy and I hate having to do any repetitive work.

Gmail Backups with fetchmail on OS X

Filed under Featured, Mac, Scripts

I use GMail as my personal email provider, and as much as I like the simple and snappy UI, the conversation views and the filtering and search possibilities, I've grown more and more worried about having all of my (important) mails stored on someone else's servers. Now, out of all of the big IT companies in the world I'd say I trust Google a heck of a lot more than anyone else, but this doesn't mean that I shouldn't take into consideration the possibility of something going wrong on their end and as a result some (or Bob forbid, all) of my mails disappearing into bit heaven.

The good news is that Google provides a nice, standard POP3 interface for downloading emails from their service, and all of the software required for downloading messages via POP is already installed in Mac OS X Leopard by default. Below I'll go through all of the steps it took me to set up periodical and automated GMail backups on my Macbook.

icalBuddy: Getting Events and Tasks from the OS X Calendar Store via the Command Line

Filed under Mac, Programming

icalBuddy example pic I'm a big fan of the "do not repeat yourself" principle, which, especially in the context of software, basically means that you should only have one place to change anything. Any highly volatile data that will be viewed from more than one location (or in more than one way) should only have one location and/or interface for changing it. This way, whenever someone, somewhere, at some point in time happens to make changes to that data, all of the views that display it will reflect that change in true automated synchronization with my cell phone to work.

I used dashboard widgets for a while for getting a quick overview of all of the events I have planned for the day plus any uncompleted tasks I might have, but soon noticed that I don't actually go and see what's up in the dashboard very often, which lead to me forgetting some things even though I had them set up as events or tasks in my calendars. The perfect place for displaying events for the day and any uncompleted tasks for me would thus be the desktop, which, even though it is most of the time obscured by a bunch of windows, I'll occasionally glance at during the day. GeekTool is the solution for displaying any textual output from the shell on an OS X desktop, and I was using that already for some other things, so all that I needed was a CLI application or script that would get the events and tasks from the calendar store and output them in a nice readable way.

Mac OS X Mouse Wheel Support for ActionScript 3 Flash Applications (v.2+)

Filed under ActionScript 3, Flex, Mac, Programming

AS3 Mouse Wheel support picture So I've finally updated the solution I've made earlier for enabling Mac OS X mouse wheel support in Flex applications to a second version. I didn't want to continue adding stuff into the original post, so I decided to write a separate post just for this new version. As you can see from the title, this version should work in any Flash project you're writing in ActionScript 3, as opposed to just in Flex projects. This change was contributed by Pavel Fljot, and all the other stuff I've added since have been added on top of that. Deployment should now be a lot easier and some features that were missing in the first version have also been added.

Automatic, Periodic Syncing with iSync

Filed under Mac, Scripts

Sync completed successfully Growl notification The first time I decided I wanted to start synchronizing my cell phone's calendar and address book with my Mac's, I noticed how iSync doesn't have a system of automatically invoking the synchronization procedure between regular intervals. I wanted to have the sync invoked automatically every 30 minutes, so I figured I had to do it myself somehow. I've had this script in place and running for, I don't know, a year and a half now, and I've used it with two different phones (the Nokia 3230 and the Nokia N82.) I'm not sure why I haven't blogged about it before, since this is exactly the kind of stuff I tend to write about here. Probably I've just forgotten is all. In any case, here it is.

Going Back to the Origin of a Downloaded File

Filed under Mac, Scripts

goToSource icon One of the biggest reasons why I prefer to use Safari as my web browser of choice on OS X is its integration with the rest of the operating system, a quite recent example of which is the tagging of downloaded files with Spotlight metadata about the location where they were downloaded from. In the latest Safari update – version 3.1 – this was extended to also apply to pictures dragged from the browser onto the local filesystem.

This metadata is most frequently used in the dialogs that are shown whenever an executable is being opened for the first time after being downloaded from the web, and it is accessible to users via the "get info" dialog box. If you have a file laying around somewhere, and you're trying to remember where you got it from, you can always look at the file info, find the "where from:" field, copy the address, switch to your browser, paste the address to the location bar, and press enter in order to get to the origin site. I knew you could read file metadata in OS X with the mdls utility, so I figured it'd be quite simple to make a little "droplet" application for streamlining the task of navigating to the origin web site of a particular file, so that's exactly what I did.

Fixing the Nokia N82 iSync Plug-In

Filed under Mac, Miscallaneous

N82 and iSync buddy picture I Recently updated my cell phone to a Nokia N82. The most positive points about it are the relative snappiness of the user interface (most Symbian S60 devices are dog slow in that department) and the quite exhaustive feature list. The build quality feels alright and the camera takes excellent pictures for a phone. One of the biggest things that I enjoyed with my previous phone (a Nokia 3230) was the nicely working synchronization with Apple's iSync, so naturally I made sure that this would also work with the N82. Apple has included built-in support for syncing the 3230 in the iSync that ships with Leopard (it was in the Tiger version as well,) so I didn't need to install anything extra to get it to work. The N82, on the other hand, is not supported out of the box, so I needed to get an iSync plug-in for it from Nokia.

Update (Jan 30, 09): A little birdie told me that the issue detailed in this post has been fixed in the latest version of the official plugin from Nokia.

Keeping AirPort Connected to a Specific Access Point

Filed under Mac, Scripts

keepConnectedToWLANAP application icon The wireless LAN access point we have at our house is an old Belkin box that only supports the 802.11b standard, which is the slowest of the few "versions" of WiFi. The speed hasn't been a big issue -- we rarely need to move large files over the internal network, and if we do, we plug in an Ethernet cable. Even the fact that it sometimes replaces web pages your browser requests with advertisements of some fantastic parental filter feature it has has not annoyed us enough to take action. What has been an issue, though, is the fact that it frequently drops connections with our Macbooks.

A "Go to Parent of Current Folder" Toolbar Button for Finder

Filed under Mac, Programming, Scripts

The “go to parent folder” button in the Finder toolbar Although the updated version introduced with Leopard significantly improves upon the one in Tiger, I still think Mac OS's Finder is lacking in several departments. I Don't feel "at home" with separate file managers (Path Finder or ForkLift, for example -- even though I do own a license to the latter, I only use it as an SFTP client,) so I've taken it upon myself to improve the experience of using Finder. The first thing that annoyed me with it was the fact that even though you could use the key combo Command(or Apple key) + Up arrow to go to the parent of the current folder, there was no button in the toolbar for it (which is exactly how I would prefer to invoke this action.) Well, due to the fact that you can drag any application to Finder's toolbar, it's quite easy to add your own buttons there.

Update (feb 13, 08): Updated the app to have a much nicer icon (made by Matti Schneider -- thanks!)

Growlnotify Leopard Incompatibility Workaround

Filed under Mac, Programming, Scripts

I Have a bunch of custom shell scripts that I use for various things, and most of them use the growlnotify utility that is distributed with Growl to display messages to the user. Unfortunately, as of this writing, growlnotify has some issues with Leopard and thus messages sent through it will be displayed only intermittently (i.e. approx. one third of all messages sent via growlnotify are not shown at all.) I Found, after a bit of googling, that you can make growlnotify send messages to Growl through the network instead of whatever local mechanism it normally uses, and have it work, even with the current (1.1.2) version. Here's the workaround I currently have in place:

An Application Bundle / Shell Script for Starting and Stopping the Tomcat Server

Filed under Mac, Programming, Scripts

toggleTomcat application bundle icon I've recently had to install tomcat on my localhost to continue developing the Flex application I'm currently doing at work since it connects to web services that are implemented in Java. I wanted an easy way to start and stop the tomcat server, so I made this nice little app for it with the help of a bash shell script and Platypus.

Update (Dec 1, 07): Due to the fact that the icon-assigning script that I've made doesn't support the 512x512 icon resolution introduced in Leopard, I've made a new version of this one, using the "seticon" utility from osxutils. Download: the app / the sources

Flex SDK Language Reference Helper Macro for jEdit

Filed under ActionScript 3, Flex, jEdit, Mac, Programming

VeryVito at turdhead.com has been writing lately about customizing jEdit for writing ActionScript, which is exactly what I've also been doing. A While ago he posted macros for referencing the help files that came with Flash CS3. Well, I don't have Flash CS3, and I use the Flex SDK to do my ActionScripting, so I took the macro he posted and modified it so that it can be used with the Flex language reference.

Update (Oct 5, 07): Now it can search from any number of AsDoc sources
Update (Oct 8, 07): Also finds documentation for methods, changing the command for opening a file in a web browser is easier
Update (Oct 10, 07): now the script searches through files, not buffers, so you needn't have all of your project's files open for it to be able to search through them

The Mac Applications I Use and Recommend

Filed under Mac

I've long though about documenting the slew of applications I've accustomed myself to using on my Macbook, but I've never really gotten around to it until now. The main reason I have for writing this kind of a list is to document these things on a remote server (or preferably several – Google, I'm looking at you) in case my laptop decides it's time to give up the ghost and I'm forced to start all over again with a new one. Writing this in my blog should accomplish this goal, and in addition it can serve as my official list of recommended applications for other Mac OS X users. So, here it is, in all its long glory.

Image Rendering: Microsoft Word 2002 vs. Apple Pages '08

Filed under Mac

Apple recently released an updated version of their iWork application suite, adding a totally new spreadsheet application - Numbers - into the mix, alongside Keynote, the venerable presentation application, and Pages, the word processor. All of these applications promise full compatibility with Microsoft Office file formats (even the new XML-based ones, which MS is desperately trying to gain "official standard" status for), which I feel is the most intriguing part of the whole offering.

Open the Current Terminal Directory in Finder

Filed under Mac, Scripts

I found this excellent AppleScript that enables you to open the current Finder folder in a new iTerm (my terminal app of choice) tab. Well, I also wanted to be able to invoke the same functionality in the other direction.

Update (Dec 1, 07): Ahem, I just found out a while ago that simply typing "open ." into the terminal will invoke this same functionality ;-) So yeah, no need for a shell script for this.

A Shell Script to Assign Icons to Files or Folders in OS X

Filed under Mac, Scripts

I've come across a few situations where I've wanted to be able to change the icon of a file or folder from the command line (e.g. in shell scripts). I also found it important to make sure that Finder is notified of this change and thus updates the file or folder so that its new icon is displayed.

Update (Nov 2, 07): It seems the method described here doesn't work in Leopard. I Wrote this python script to accomplish the same task using a different method. The difference between these two is that with this new version, the source file has to be an actual image (i.e. jpeg or png, for example) instead of an .icns file.

Update (Dec 1, 07): The methods described here do not support the 512x512 resolution introduced in Leopard, but the "seticon" utility in osxutils seems to, so you should definitely use that instead.

Disabling Safe Sleep in OS X

Filed under Mac, Scripts

I’ve had problems with my MacBook hanging with an empty black screen after waking up from sleep. This usually happens when I make it go to sleep by closing the lid and later wake it up by opening it (approximately 20% of the time). Closing the lid, waiting until the sleep light starts slowly blinking again (signaling that the OS has finished initializing sleep mode) and then opening it again has always solved the problem, but it is still really annoying.

Update: Ok, it's now been almost a month and my laptop has not hung once when waking up from sleep, so I guess I can pretty much say that disabling safe sleep did the trick.

Update (Dec 1, 07): This problem has been fixed in Leopard. You can still use this method for disabling safe sleep, though. The pmset command seems to suffice.

OS X Mouse Wheel Support for Flex 2 Applications

Filed under ActionScript 3, Flex, Mac, Programming
Note: This version of this solution is deprecated. I've made a separate post about the new version, which you can find here.


In my current job I have been programming user interfaces for applications that display networks of data (as in nodes, links etc.) with the Adobe Flex framework, and the UI paradigm I have been utilizing is a kind of a Zoomable User Interface (ZUI). The idea there is to enable the user to view and manipulate objects on a two-dimensional plane, and navigate around that plane by zooming and panning.

Now, the easiest way (at least for me) to control the zooming is to use the mouse wheel. Mouse wheel support for Flex is implemented by registering an event listener of type MouseEvent.MOUSE_WHEEL with the DisplayObject that would dispatch the event. Sadly, mouse wheel support is not available in the Mac OS X version of Flash Player. This prompted me to create a custom solution, as my main computer is a MacBook and I would like to be able to test the mouse wheel navigation with my development machine.

Update: The javascript now works with more browsers than just Firefox 2 and Safari 2. I Tested it, in addition to those two, with Opera 9, Camino 1.5 and Omniweb 5.5, and it seems to work in all of them now.

Update #2: Changed the javascript code to also work with Safari 3 beta. When using it, small movements with the wheel do not invoke any action, so you'll have to roll it a bit further to make the app respond.

Update #3: Added statement about licensing the code under the MIT License as per request of Philip Flip Kromer

Update #4 (feb 8, 08): If you're looking for AS3 (not Flex) OS X mouse wheel support, check out PixelBreaker.com.

Update #5 (feb 12, 08): Fljot sent me a version of this that works also in non-Flex AS3 projects. He also fixed some issues in the code related to the automatic registration of listening objects. You can find him here.

Changing Application Settings in OS X Based on (Network) Location

Filed under Mac, Scripts

MarcoPolo switching the location I Generally use my laptop in three different locations:

Changing application settings manually every time I arrive at a new location gets tiring really, really fast. The location settings you can create in OS X can specify network-related settings (proxies etc.) on a system level for all the different locations you enter, but then you of course have to manually switch the current location setting every time. I First used Quicksilver for that, but then found out about MarcoPolo, which is an excellent open source application that can change your network location (and initiate any other specified actions) automatically based on a bunch of rules using evidence sources (like Wi-Fi access point SSID or the first octets of a DHCP-assigned IP address) that you can set up. Setting up MarcoPolo and defining the rules was really straightforward, and its operation has been quite stable from the day I've started using it.

The problem I had next was that I used two applications that are cross-platform and thus not designed to take advantage of any OS-wide settings: Firefox and Subversion. So, these applications have their own settings management and I needed a way to make some of their settings (namely the proxy servers) change automatically along with everything else.

Update (jan 14, 2008): I Rewrote this script in Python a while back. It's now much nicer. Get the updated version here.

Update (aug 17, 2008): Refined the text in the post a bit according to my larger amount of experience with this. Changed link to point to the latest version of the script.

Categories