Page 1 of 1

Use of Event wildcard in code ?

Posted: Sat Dec 23, 2017 5:49 pm
by Snowbird
Hello,

I'm struggling a bit, I don't know how to use the wildcard with an event :

Code: Select all

if eg.event.string == "System.PowerProfile.*" :
    my code here
I want it to match all these events :
System.PowerProfile.HighPerformance
System.PowerProfile.PowerSaver
System.PowerProfile.Balanced

I've checked the wiki but there's no mention about the use of wildcard directly in the code :
http://www.eventghost.net/mediawiki/ind ... _Events.29

how can I do this ?
Thank you

Re: Use of Event wildcard in code ?

Posted: Sat Dec 23, 2017 7:51 pm
by yokel22
I'm not sure if what you want is possible from script. You can use startswith() or the re module to accomplish this though.

Code: Select all

string = "System.PowerProfile."
match = eg.event.string.startswith(string)
if match == True:
     # wildcard was met, execute code
     print 'wildcard'

Re: Use of Event wildcard in code ?

Posted: Sun Dec 24, 2017 1:11 am
by kgschlosser

Code: Select all


import fnmatch

if fnmatch.fnmatchcase(eg.event.string, 'Some.*.Event.?ame'):
    # do your code here
    
or this if you are looking for a specific phrase in the eg.event.string

Code: Select all

if 'Some.Event' in eg.event.string:
    # do your code here

Re: Use of Event wildcard in code ?

Posted: Sun Dec 24, 2017 10:21 am
by Snowbird
Thanks to both of you ;)

I picked kg method, it worked right away !

PS. Maybe it's worth adding this example in the wiki ? it could be helpful to others I think.

Merry X-mas everyone ! :)