I couldn't find other questions about this, so I thought I would post my solution here in hopes of helping others. If I have missed something simple that makes this easier please let me know.
PROBLEM:
I want to do something when a certain app has a notification.
SOLUTION:
Write a for loop through all the notifications. In the output use an IF statement to only print something if the name of the app for this notification matches what you are looking for. Then, if that for loop produces your value, you can act upon it. In some cases you might want to use a simple "true" output, that the for loop caught a notification from your app, other cases you may want to print the index (or i) of the notification so you can use it later to get other information about the notification.
$if(
fl(0, ni(count)-1, "i+1",
"if(ni(i, app)=APP NAME, true)",
"")
=true, ALWAYS, NEVER)$
In this first example, I am looping through only dismissable notifications, and using the app name. If a notification is found with that app name, the for loop prints out true, once it is done, the outer if statement checks if the output was true. If so, I am printing out ALWAYS for a visible option. Otherwise print out NEVER.
This example does have some issues. If there is more than one notification with the same app this will not work. The reason is, the for loop will print out "truetruetrue", and thus our outer if statement will not work.
$if( tc(cut,
fl(0, ni(count)-1, "i+1",
"if(ni(i, app)=APP NAME, true)",
"")
, 4)=true, ALWAYS, NEVER)$
The addition of the tc(cut) function allows me to look at just the beginning 4 characters in the string. This then, will tell you if at least one notification exists for the app name in question.
Get Index of Specific App Notification
Finally, you may want take more info from that notification, like the image or text. In this case, you'll set up a global value to capture the index of the notification so you can use it later.
GLOBAL Number
$fl(0, ni(count)-1, "i+1",
"if(ni(i, app)=APP NAME, i)",
"")$
This will store the index number of the notification. However this has the same flaw as before. IF there is more than one notification for the same app. For this we can use this formula instead:
$tc(split,
fl(0, ni(count)-1, "i+1",
"if(ni(i, app)=APP NAME, i+.)",
""),
., 0)$
By adding another character, or split character to the output of the index we can then split that wit the outer tc(split)
function. Stay away from using special characters that are used in function like [, + -] etc.. Finally, the zero (0) at the end tells us which index to grab. This will give us the first notification with the lowest index. However, by combining these function calls, you could get the number of notifications for an app, then loop through each index and do something.