how to make text replacement in automator (regex)
Asked Answered
W

3

7

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!

Wallasey answered 28/11, 2010 at 6:56 Comment(0)
W
0

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

Wallasey answered 2/1, 2011 at 14:25 Comment(1)
Apple is about to drop the native PHP support, as well as other scripting languages like Python, Ruby and Perl. In the future, you need to manually install PHP to use it in Automator scripts.Upmost
F
2

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.

Foust answered 28/11, 2010 at 16:28 Comment(0)
C
0

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.

Calondra answered 28/11, 2010 at 17:44 Comment(0)
W
0

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

Wallasey answered 2/1, 2011 at 14:25 Comment(1)
Apple is about to drop the native PHP support, as well as other scripting languages like Python, Ruby and Perl. In the future, you need to manually install PHP to use it in Automator scripts.Upmost

© 2022 - 2024 — McMap. All rights reserved.