hasseg.org

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.

Use Unicode Emoji as Icons in Native iOS Apps

Filed under Featured, iOS, Programming

A while back, I wrote about using unicode emoji characters as icons in web apps. The big caveat with that was that these characters were only available on iOS devices, which made the trick much less useful in a web app, which of course are generally meant to be more or less cross-platform. If you're developing a native iOS app, though, using these standard colorful bitmap emoji characters as icons is a much more realistic proposition, because you can be sure that all the devices your app runs on will have them available. In this post I will show how to easily do this.

jEdit Syntax Highlighting Mode for the Peg/Leg Parser Generator 'Leg' Syntax

Filed under jEdit, Programming

jedit icon I've been working on a fast and embeddable Markdown parser that can be used for syntax highlighting in editors, based on the PEG grammar from John MacFarlane's peg-markdown compiler project. The grammar is written in leg, a syntax for the peg/leg parser generator by Ian Piumarta, and to make my work with this new syntax a bit more pleasant I implemented a jEdit mode for it.

jEdit Macro for Opening the File Browser at Current Buffer's "Project Root" Directory

Filed under jEdit, Programming, Scripts

When I'm working with code in jEdit, my editor of choice, I like to keep the file browser open and docked to the left side of my editor window. When I'm switching between files -- often belonging to different projects -- I find myself reaching for the mouse in order to manually navigate the file browser to the root folder of the project the currently open file belongs to. I started doing this so often that I decided to whip up a small macro to do it for me.

Update (April 4, 2011): Set file browser to directory of current buffer if version control root cannot be found.

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.

Use Unicode Emoji as Image-Free Icons in iOS Web Apps

Filed under iOS, Programming, Scripts

In version 2.2 of iOS — Apple's "mobile" operating system used in the iPhone, iPod Touch and iPad — support for Emoji was added. These small 12x12 pixel icons are meant to be used in text messaging in Japan but because they're implemented simply as unicode symbols in the device they can be used as icons when we know they're available.

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.

Getting a List of Installed Fonts with Flash and Javascript

Filed under ActionScript 3, Flex, Miscallaneous, Programming

When implementing the feature in the icalBuddy examples page where the font used for the output examples could be changed interactively I needed to get a list of all the fonts installed on the current user's computer. This blog post from 2006 explains how to do it, but it refers to the deprecated ActionScript 2 API so I had to figure out how to do it with AS3.

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, Declarative UML Sequence Diagrams

Filed under jEdit, Scripts

wsd-example-diagram-small I recently had to create a few UML sequence diagrams, and I decided that I didn't want to spend too much time manually tweaking and fixing the diagrams themselves (which is what I probably would've done, had I used OmniGraffle or something similar), but instead focus on the content — the depicted workflow itself. This is when I remembered the bookmark I had in my browser for the Web Sequence Diagrams online service.

Markdown and POD Syntax Highlighting Modes for jEdit

Filed under jEdit

In The Pragmatic Programmer¹, the authors Andrew Hunt and David Thomas empasize the power of plain text, as well as "generators" that take the canonical form of some document and generate different representations of it. This is very much in line with the way I like to work with a lot of documents, which is why I've been using the Markdown and POD (Plain Old Documentation) syntaxes for a couple of things. As jEdit is the editor I prefer to use for working with most plain-text formats, I wrote highlighting modes for it for these two syntaxes.

Update (April 23, 09): Updated the Markdown mode with slightly better handling of code blocks and list item paragraphs as well as some comments about problems therein (see below in the post for more info on this).

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.

fcshctl: the Flex Compiler Shell Controller

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

Introduction

Like I've mentioned before in this blog, I develop Flex applications using the Flex SDK and jEdit instead of Adobe's Flex Builder IDE. This setup has worked very well for me but one annoying issue I've had to deal with because of this is the slow compilation speed: every time I make a small change into one of my projects and recompile it, the mxmlc compiler (that my build scripts are calling) has to load the JVM into memory and recompile my whole project from scratch, which obviously takes a while. Compiling things in Flex Builder is a lot faster, and the reason for that is the Flex Compiler Shell, which it uses for compilation instead of mxmlc.

Update (Version 0.5.1, Mar 17, 09):
  • Display a "compiling..." message before sending fcsh a compilation command in order to let the user know that something is going on and that they should wait instead of just killing the process.
  • If the log file exists when fcshctl runs, check if there are any other fcshctl instances running, and if not, assume that the log file has been orphaned, delete it and continue.
  • Exit with status code 0 ("ok") if fcsh output ends in the "Nothing has changed since the last compile" message.

Saving and Accessing Version/Compilation Information with Flex Applications

Filed under ActionScript 3, Flex, Programming

On several occasions while developing Flash applications I've run into problems with proxy/cache servers. The pattern is usually something like this:

  1. I notice a bug in an application that only occurs when running it on the server
  2. I debug the application, find the bug and issue a fix
  3. I deploy the new version that contains the fix onto the server
  4. I empty the browser cache and run the app on the server again, noticing that the bug seems to persist
  5. I wonder if the version I'm seeing is indeed the version that has the fix, or an older build served to me by some cache server between my workstation and the server
  6. I have to resort to stupid trickery (comparing md5 hashes of .swfs or something) in order to find out

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.

Quick File Tagging in OS X with Punakea (& Tagger)

Filed under Miscallaneous

Even though I am a little pedantic in some ways (like most engineers are, I suppose,) I always seem to have trouble organizing the files on my computer(s) with any kind of reasonable folder structure or naming convention. I often find myself desperately trying to find a specific file that I know I have somewhere but I'm not sure where, and sometimes I just want to find a bunch of files that are somehow related but not actually saved into the same folder. These are problems that tagging is trying to solve (and doing a reasonably good job at it, I might add.)

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!)

Collapsible Panel Component for Flex

Filed under ActionScript 3, Flex, Programming

Here's an another post in the same vein as my previous one: this time, the component I'm sharing is a Panel subclass that allows for collapsing and expanding its contents. What this means is that the user can click on the header of the Panel to make it toggle between an open or closed state, with a smooth animation.

Vertical TabNavigator Component for Flex

Filed under ActionScript 3, Flex, Programming

I Some time ago ran into a situation with a Flex app I was working on where I needed to use a TabNavigator component, but have its TabBar situated on the left or right side of the ViewStack (instead of on the top, where it is in the default TabNavigator.) I Could not find any workable solutions online (the ones I did find could pretty much be described as ugly hacks,) so I made my own by extending the default TabNavigator. I Submitted this component to the flexlib project, but since it has pretty much been ignored in the discussion group, I thought I'd post it here to make it available to the general public.

Update (same day as orig. post): Added simple demo and example code on how to use the component. Added comment about using embedded fonts.

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:

ActionScript 3 Support for jEdit's SideKick Plugin Through Exuberant Ctags

Filed under ActionScript 3, Flex, jEdit, Programming

Today VeryVito made a post on his blog that I had been waiting for a while now: he had just written ActionScript 3 support for Exuberant Ctags, which means proper SideKick plugin support for jEdit when editing AS3 with it. He also made nicer icons for use with the CtagsSideKick, so you should definitely check his stuff out if you use (or plan to use) jEdit for editing AS3.

However, after starting to use the SideKick plugin with the modified, AS3-supported version of Ctags while doing my work, I found a few small rough edges in the ActionScript support he had made:

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

jEdit Macros for Running Compilers

Filed under Flex, jEdit, Programming, Scripts

compileMxml shell script displays Growl notifications I've been using jEdit as my ActionScript 3 editor for a while now. I Like the extension and customization possibilities it gives me, and I've used them to create macros for compiling my Flex applications and then bound them to specific keyboard shortcuts to enable quick access to running the compiler.

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