Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Trigger macro if (eg.variable == 0)

If you have a question or need help, this is the place to be.
Post Reply
vali_ics
Posts: 5
Joined: Mon Apr 21, 2014 3:40 pm

Trigger macro if (eg.variable == 0)

Post by vali_ics »

Hello guys.
I'm new to python but i have some questions about eventghost and i want to be clear in future.
I have like this 3 macros based on some applications.

Code: Select all

eg.ProgramName = 'Chrome'

Code: Select all

eg.ProgramName = 'Opera'

Code: Select all

if (eg.ProgramName == 'Chrome'):
          eg.TriggerEvent ("ChromeTrigger")
elif (eg.ProgramName == 'Opera'):
          eg.TriggerEvent ("OperaTrigger")
1. How can i trigger the last macro based on eg.ProgramName variable ?
I'm thinking to create a eg.TriggerEvent ("ProgramName") and trigger the last one based on Main.ProgramName event.
Is this viable or it's another easy way ?

2. Should i make all variable like this eg.Variable or eg.globals.Variable ?
On web i find only eg.globals.Variable, i want to know how should i use in future.

Thanks, have a good day!
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Trigger macro if (eg.variable == 0)

Post by Pako »

vali_ics wrote:2. Should i make all variable like this eg.Variable or eg.globals.Variable ?
On web i find only eg.globals.Variable, i want to know how should i use in future.
Although particular constructions

Code: Select all

eg.ProgramName = 'Chrome'
works, it is very inconvenient.
It may happen that you accidentally overwrite an important attribute of the object eg.
Always use

Code: Select all

eg.globals.ProgramName = 'Chrome'
vali_ics wrote:1. How can i trigger the last macro based on eg.ProgramName variable ?
I'm thinking to create a eg.TriggerEvent ("ProgramName") and trigger the last one based on Main.ProgramName event.
Is this viable or it's another easy way ?
In this case, it is probably best to use Python dictionary:

Code: Select all

myDict={'Chrome':'ChromeTrigger','Opera':'OperaTrigger'}
eg.TriggerEvent(myDict[eg.globals.ProgramName])
Pako
vali_ics
Posts: 5
Joined: Mon Apr 21, 2014 3:40 pm

Re: Trigger macro if (eg.variable == 0)

Post by vali_ics »

Thanks a lot @Pako.
I have a question again. I can't find anything like this.

1. Trigger - > Main.OK.Computer.google wikipedia (trigger it's from a raw_input)
2. Python Script

Code: Select all

command = 'Main.OK.Computer.google wikipedia'
search = command.split(' ')
if command.find('google'):
    print('working') #just for debugg
else:
    print('not working') ##just for debugg
How can i get the Trigger Name into a variable ?
I tried with eg.event.payload but don't work.

Code: Select all

command = trigger_name_var
I can make a trigger with a dynamic variable ? And how ?

I seached google a lot but i can't find anything for this.
Post Reply