Check wether notification contains certain word (s)

Post your questions and help other users.

Moderator: Martin

Post Reply
gmain
Posts: 2
Joined: 05 Jun 2013 00:14

Check wether notification contains certain word (s)

Post by gmain » 05 Jun 2013 00:38

Hi, I would like to filter notifications by checking if a notification title contains a certain word.

I know that by using the following in an expression, I can check whether the WHOLE title is the word itself:

title == "notificationtitle"

I would like to know how to check if a notification title even just PARTLY matches the word im looking for. I was thinking I have to add something between the quotes, but i wouldn't know what. (Im new to automagic)

How do I do this?

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Check wether notification contains certain word (s)

Post by Martin » 05 Jun 2013 20:09

Hi,

You can use a function in a condition Expression to check if a variable contains the text 'xyz':
indexOf(variable, "xyz")!=-1;

or if a variable starts/ends with xyz:
startsWith(variable, "xyz");
endsWith(variable, "xyz");


or more flexible with a regular expression:
matches(variable, ".*xyz.*");

All available functions are listed in the help page of action Script (scroll down to section Functions):
http://automagic4android.com/en/help/co ... ion_script

Regards,
Martin

gmain
Posts: 2
Joined: 05 Jun 2013 00:14

Re: Check wether notification contains certain word (s)

Post by gmain » 05 Jun 2013 21:49

Hey Martin,

I had already written a code that checks the contents of a string, reading character by character to see if it contains the sequence of characters that I'm looking for (I guess the same method that the functions use to get the job done). It works, but using indexOf() is way easier!

Thanks!

Post Reply