is there something akin to regEx in applescript, and if not, what’s the alternative?

Don’t despair, since OSX you can also access sed and grep through “do shell script”. So:

set thecommandstring to "echo \"" & filename & "\"|sed \"s/[0-9]\\{10\\}/*good*(&)/\"" as string
set sedResult to do shell script thecommandstring
set isgood to sedResult starts with "*good*"

My sed skills aren’t too crash hot, so there might be a more elegant way than appending *good* to any name that matches [0-9]{10} and then looking for *good* at the start of the result. But basically, if filename is “1234567890dfoo.mov” this will run the command:

echo "1234567890foo.mov"|sed "s/[0-9]\{10\}/*good*(&)/"

Note the escaped quotes \” and escaped backslash \\ in the applescript. If you’re escaping things in the shell you have to escape the escapes. So to run a shell script that has a backslash in it you have to escape it for the shell like \\ and then escape each backslash in applescript like \\\\. This can get pretty hard to read.

So anything you can do on the command line you can do by calling it from applescript (woohoo!). Any results on stdout get returned to the script as the result.

Leave a Comment