开发者

how to make text replacement in automator (regex)

I am making an Automator application and I need to rep开发者_开发技巧lace some text based on a certain criteria. I am wondering if there is an Automator action for performing a regex text replacement.

If not, I always have the option to run an AppleScript that can do this, but I really don't know how to write AppleScript code.

Thanks!


There's no dedicated Automator action for this, but you can use the "Run Shell Script" action. It can receive its input on stdin or as arguments, and you can just use sed, awk, perl, ruby, or whatever you're comfortable with to do the replacement.


I recommend the TextEdit Automator Action Pack by a company called Automated Workflows.

The downside is that it is not free but it's not too pricey. I think there is a demo mode so you can at least check it out.

You're not able to enter your own regular expressions but the actions provided cover almost everything you need. I use the actions for every single Automator app I make which involves text files.

Alternatively, if you want to use your own regex commands you can install a scripting addition for AppleScript made by a company called Smile. It's called Satimage and it allows regular expressions to be used in AppleScript. Visit the Satimage dictionary for usage.

If you install that scripting addition then you can include any regular expression you want in Automator by including an AppleScript action and then pass variables back and forth, though I think the TextEdit Automator pack will be easier and more efficient.


Since I posted this question I realized that one can use PHP code in Automator scripts. It's a great way to do all kinds of stuff (even though it's a bit freaky how you can write or delete files this way).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜