hasseg.org

Scripts

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.

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

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.

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.

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.

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.

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.

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

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.

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.

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