문제

I am making an Automator application and I need to replace 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!

도움이 되었습니까?

해결책 3

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top