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

1 comment:

  1. Gambling Sites and Gambling Sites for South Africa - Airjordan20 Retro
    The air jordan 18 stockx sale South African government's bestest air jordan 18 retro red suede efforts air jordan 18 retro toro mens sneakers online shop to create a world of online gambling have been make air jordan 18 retro red suede hindered by the South African government's failure to show to buy air jordan 18 retro racer blue respond to the

    ReplyDelete