Friday, August 21, 2009

Using regular expressions in Applescript

I finally got around to fix the issue with escaped spaces in windows paths, se previous post.

This required some search and replace in strings, which oddly enough isn't implemented in Applescript. But since Applescript can run any shell command, this is easily circumvented. I use the "sed" command, as follows:
set escapedPath to do shell script "echo " & quoted form of MacPathString & " | sed 's/ /\\\\ /g'"

The syntax is "sed s/find/replacement/g source", where g is the regexp global flag. The "|" is the unix "pipe" operator which forwards previous output to the following command, i.e. the "echo" command results are piped into "sed".

Saturday, April 25, 2009

Converting Windows paths to Mac paths and vice versa [updated]

In many companies there are network file servers which are mapped to drive letters in windows, for instance "K:" and to a volume name in Mac OS X, for instance "Clients". People working on either platform need to share content, and thus send links to folders on the server. But the urls on the mac and in windows doesn't match.

I have created a small Mac application that solves this issue. It's a simple Applescript application and the source is editable.

Simply drag the application bundle to your /Applications folder and drag it onto the dock to create a shortcut.

Open the application in the Applescript editor and change the following two lines to the values of your network drive:

set windowsDriveLetter to "K:"

set macVolumeName to "Clients"

It has two modes, Windows path to Mac path, and Mac path to windows path.
  1. Click in the icon to start the application. A dialog appears, where you can enter a windows path. When clicking "Ok", a new finder window pops up with the entered folder.
  2. Drag a folder onto the dock icon. A dialog appears where the corresponding windows path is selected and ready to copy paste.
Download it here

I really should create a nice icon for it...

[update on 21 aug 2009]
Spaces in windows path are now correctly escaped with "\ " in the corresponding mac path.

[update on 3 sep 2009]
A convenient way of doing this, as pointed out by Gerhard Schoenthal, is to create an Automator Service action which copies the path to the clipboard, especially since the Service menu became contextual in Snow Leopard. I have basically just modified the approach found here, and added the windows path conversion.

Following the steps below will create a new menu item under "Services", which will be visible when a file or folder is selected in the finder.

Download this file, and copy it to Library/Services under you user home folder.

Or you can create the service in Automator, and add the following Applescript Snippet:

on run {input, parameters}

-- SETTING: Change the windows drive letter here
set windowsDriveLetter to "K:"

tell application "Finder"
set itemPath to selection as string
set my text item delimiters to ":"
-- Skip /Volumes and DriveName, i.e. start from 2
set filePath to text items 2 through -1 of itemPath
set winPath to {windowsDriveLetter} & filePath
set my text item delimiters to "\\"
set finalPath to (winPath as text)
set the clipboard to finalPath
end tell

return input
end run

Thursday, February 26, 2009


I learned today that the ADDED_TO_STAGE event constant was not added until flash player 

This can typically cause the error TypeError: Error #2007: Parameter type must be non-null. at for people with flash player 9 prior to 9.0.28, for instance flash player 9.0.16. (Yes, I have added the versions to help google find this post.)

I hope this post can help someone find the problem :-)

Wednesday, February 25, 2009

A fundraiser for the Church of Sweden

The last few weeks I have been working on a site for a fundraising campaign by the Swedish Church. The theme of the campaign is water. You can create your own fund, invite you friends to help you fill the buckets with water, and all funds are part of the big campaign fund.

The main challange of the production was making the payment methods run smoothly. Contributions can be made in to ways: using credit cards and direct bank payments through PayEx, or they can be made by sms. The PayEx system transaction requires the visitor to leave the campaign site, enter their credentials at the PayEx site, and then return to the campaign site. Data persistance and maintaing state is obviously an issue that needs to be handled throughout the transaction. I think we came up with a pretty good solution.

I also created an AS3 package with a complete set of classes for using PayEx, I will post that on the web somewere if someone is interested. (PayEx only supplies java, .net and php versions.)

Thursday, February 19, 2009

Unpacking my Moleskine Helvetica

So, I like limited editions, typography and Moleskines. I could of course not resist the limited edition Helvetica Moleskine :-) I only wish the pages were not ruled but blank... More unpacking pictures can be found here:

Monday, January 5, 2009

TIWC # 1: A swf remote controller in AIR

You know those things that would be really useful to have in most projects, but is not really part of the actual project, thus there is no time to develop them? In this "Things I want to create" series, I will outline a few such ideas. It would be nice to make them into open source projects, and I will if I ever find the time.

Some features on a website requires the swf to be embedded in html, and displayed in a browser. For instance resizing the whole swf, swfaddress navigation, cookies etc. But when you are developing, it can be convenient to run the site within the authoring environment, i.e. not in an html container. It is also quite common that the html container is created much later in some cms that you don't really care about.

The idea is to create an AIR utility that can reside in the mac menu bar or the windows toolbar. The site swf then communicates with the utility through local connection. The utility would have a minimal interface allowing you to control certain parameters and actions on the swf. An api for the swf would of course need to be created as well.

Features I would like to have are:
  • Sound on/off (when testing, you don't want the sound to play, but you don't want to forget to set the default sound to on either)
  • Goto swfaddress deeplink (and default startlink). Preferably a drop down of available urls, populated from the swf. (If more than one developer is working on different parts of a site that shares the same swf, settings the default deeplink could be very useful)
  • Set flashvars

Sunday, January 4, 2009

Buy a used Volvo

Just before christmas we launched a new site for Volvo sweden, where you can search for a used car. The site is a flash front connected to the swedish site backend.

The design might not be spectacular, but if you compare the flow of interaction when searching and tweaking parameters to the native interface of, I believe we did a pretty good job.

Flash-wise, the site is a textbook example of the benefits of using the PureMVC AS3 framework