Ways To Modify Only Part of a String?

Seeking most efficient way to switch just part of a sentence, most likely verbs.

A variable will either get passed in or set to match triggers with text. Examples are "turn off computer," "turn off tablet," or "turn off Nintendo Switch," etc. Alternatively, they'll be "open bedroom window," "open kitchen window," etc.

The action(s) I want to refine is to take one of those at a time and set a variable to the opposite. So take "turn off tablet" and make it into "turn on tablet" or, if not too much trouble, "turn tablet back on."

I already have actions set up like the following.
ACTIONSet variable named switch_to to "close window"
ACTION CONSTRAINTVariable named switch_from contains "open window"

How exactly do I append/prepend the string so I don't have to create an action for each possibility?
 

Dm114

Well-known member
Seeking most efficient way to switch just part of a sentence, most likely verbs.

A variable will either get passed in or set to match triggers with text. Examples are "turn off computer," "turn off tablet," or "turn off Nintendo Switch," etc. Alternatively, they'll be "open bedroom window," "open kitchen window," etc.

The action(s) I want to refine is to take one of those at a time and set a variable to the opposite. So take "turn off tablet" and make it into "turn on tablet" or, if not too much trouble, "turn tablet back on."

I already have actions set up like the following.
ACTIONSet variable named switch_to to "close window"
ACTION CONSTRAINTVariable named switch_from contains "open window"

How exactly do I append/prepend the string so I don't have to create an action for each possibility?
It should be very easy with 'MacroDroid Specific > Text manipulation > Replace all' (Regex). As the words to replace are always the same (on/off | open/close) just replace them (surrounded or followed by space) with the opposite word and a constraint as in your example. So you'll have 4 actions+constraints (i.e. 4 double lines): on→off, off→on, open→close, close→open

I suggest to include space(s) to the constraints as well as to the replacement syntax to avoid errors such as 'window is opening'→'window is closeing'...
 
Top