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.

problem with Start Application macro running twice

If you have a question or need help, this is the place to be.
Post Reply
JohnOrion
Posts: 3
Joined: Wed Aug 10, 2016 4:37 pm

problem with Start Application macro running twice

Post by JohnOrion »

I have issues with my USB ports on my motherboard and they like to randomly disconnect and reconnect. I use a USB device (modem) that causes issues with sleep when the program CallClerk is launched. Since it randomly disconnects I found that when it reconnects with the CallClerk program is running, the devices listed in powercfg /requests that used to interfere with the sleep process no longer are there and my computer will enter sleep properly (Oh btw, in Windows 10 the powecfg /requestsoverride doesn't work anymore). The problem was you had to go into the program and use it to rescan the device for the program to see it again. The maker of CallClerk (absolute amazing customer support) wrote a small addition to the program called ccRescan that does this with one click. I came across EventGhost and I can use it to run the ccRescan any time it sees the device connect so now the process is automated and will function even if I don't notice that my USB glitched.

The problem I have is the device shows 2 items when it connects:

Code: Select all

System.DeviceAttached [u'\\\\?\\USB#VID_0BEF&PID_0004#HD00USGR01101207006277#{a5dcbf10-6530-11d2-901f-00c04fb951ed}']
System.DeviceAttached [u'\\\\?\\HID#VID_0BEF&PID_0004&MI_05#7&3a826eb7&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}']
I created a Start Program macro and added one of the devices but when it executes it runs ccRescan twice.

Code: Select all

System.DeviceAttached [u'\\\\?\\USB#VID_0BEF&PID_0004#HD00USGR01101207006277#{a5dcbf10-6530-11d2-901f-00c04fb951ed}']
   Start Program: ccRescan.exe
      Start Program: ccRescan.exe
Task.NewWindow.CallClerk
Task.Deactivated.CallClerk
Task.Activated.CallClerk
System.DeviceAttached [u'\\\\?\\HID#VID_0BEF&PID_0004&MI_05#7&3a826eb7&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}']
   Start Program: ccRescan.exe
      Start Program: ccRescan.exe
Task.Deactivated.CallClerk
Task.ClosedWindow.CallClerk
Task.NewWindow.CallClerk
I have tried to make the System.DeviceAttached with the USB as the trigger and have tried with using the HID as the trigger .... I have even tried holding ctrl and selecting both and dragging them to the tree making one trigger. Any way I try it always runs it twice.. even with the "wait until application is terminated before proceeding" box checked. It really isn't a big deal because it still works ... I was just wondering if there was a way to only get it to run ccRescan once.

Sorry I'm brand new to this program so if more information is needed please let me know and I will be glad to provide it.
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: problem with Start Application macro running twice

Post by kgschlosser »

here is what i need you to do.

copy and paste the code below into a python script. that's located under the add action dialog, EventGhost tree item
then right click on the action called

Start Program: ccRescan.exe

and select copy as python and paste it into the spot noted in the code below.

put the newly created script into the macro that has the System.DeviceAttached event.

i am going to make this really easy so at the top of the script is going to be DEVICE =

you can swap out what is after the = with whatever device data is in the payload. so you may find that even though 2 are shown only one will work properly. because the physical device relies on more then one windows driver and you need to have all of the drivers running before you program will work. so usually grabbing the last one listed will do the job. i am going to preset it to that

Code: Select all

DEVICE =  '\\\\?\\HID#VID_0BEF&PID_0004&MI_05#7&3a826eb7&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}'

if eg.event.payload[0] == DEVICE:
    COPYANDPASTEHERE

make sure you preserve the spacing for the copy and paste. there has to be 4 spaces before that command you paste in there. is there isn't you will get an indentation error.

that will do what you need it to do


have fun

K
If you like the work I have been doing then feel free to Image
JohnOrion
Posts: 3
Joined: Wed Aug 10, 2016 4:37 pm

Re: problem with Start Application macro running twice

Post by JohnOrion »

As I said .. I'm new to this and have no idea what you are saying here.

I mean .. yeah I understand what I need to do but ... have no idea how to do it. The only file I have that has anything to do with this item is Custom.xml which looks like this:

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1710" Guid="{A2FA8D3F-40C5-4529-AEC2-BB8869A0FD8A}" Time="1470852097.65">
    <Autostart Name="Autostart" Expanded="True">
        <Plugin Identifier="Task" Guid="{D1748551-C605-4423-B392-FB77E6842437}" File="Task">
            gAIpLg==
        </Plugin>
        <Action>
            EventGhost.EnableExclusive(XmlIdLink(-1))
        </Action>
        <Plugin Identifier="Process" Guid="{82BADF9F-D809-4EBC-A540-CCBF7563F8DF}" File="ProcessWatcher">
            gAIpLg==
        </Plugin>
    </Autostart>
    <Macro Name="Start Program: ccRescan.exe" Expanded="True">
        <Event Name="System.DeviceAttached" />
        <Action>
            System.Execute(u'C:\\Program Files (x86)\\CallClerk\\ccRescan.exe', u'', 3, False, 2, u'C:\\Program Files (x86)\\CallClerk', False, False, u'', False, False, False, False)
        </Action>
    </Macro>
</EventGhost>
I copied and pasted the Start Program: ccRescan.exe which looks like this:

Code: Select all

eg.plugins.System.Execute(u'C:\\Program Files (x86)\\CallClerk\\ccRescan.exe', u'', 3, True, 2, u'C:\\Program Files (x86)\\CallClerk', False, False, u'', False, False, False, False)
Now I'm lost ...

I created a script by going into "add macro" then selecting Python Script which looks like this:

Code: Select all

DEVICE =  '\\\\?\\HID#VID_0BEF&PID_0004&MI_05#7&3a826eb7&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}'

if eg.event.payload[0] == DEVICE:
    eg.plugins.System.Execute(u'C:\\Program Files (x86)\\CallClerk\\ccRescan.exe', u'', 3, True, 2, u'C:\\Program Files (x86)\\CallClerk', False, False, u'', False, False, False, False)


now the Custom.xml looks like this:

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1710" Guid="{F3111992-B9EF-49E6-89BA-19D1511936DF}" Time="1470930128.07">
    <Autostart Name="Autostart" Expanded="True">
        <Plugin Identifier="Task" Guid="{D1748551-C605-4423-B392-FB77E6842437}" File="Task">
            gAIpLg==
        </Plugin>
        <Action>
            EventGhost.EnableExclusive(XmlIdLink(-1))
        </Action>
        <Plugin Identifier="Process" Guid="{82BADF9F-D809-4EBC-A540-CCBF7563F8DF}" File="ProcessWatcher">
            gAIpLg==
        </Plugin>
    </Autostart>
    <Macro Name="Start Program: ccRescan.exe" Expanded="True">
        <Action>
            EventGhost.PythonScript(u"DEVICE =  '\\\\\\\\?\\\\HID#VID_0BEF&PID_0004&MI_05#7&3a826eb7&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}'\n\nif eg.event.payload[0] == DEVICE:\n    eg.plugins.System.Execute(u'C:\\\\Program Files (x86)\\\\CallClerk\\\\ccRescan.exe', u'', 3, True, 2, u'C:\\\\Program Files (x86)\\\\CallClerk', False, False, u'', False, False, False, False)")
        </Action>
        <Action>
            System.Execute(u'C:\\Program Files (x86)\\CallClerk\\ccRescan.exe', u'', 3, True, 2, u'C:\\Program Files (x86)\\CallClerk', False, False, u'', False, False, False, False)
        </Action>
    </Macro>
</EventGhost>
With this set up this way ... ccRescan now runs 3 times instead of 2
If I try to remove the System.DeviceAttached from tree so there is only Python Script and Start Program: ccRescan.exe it doesn't run at all.
I tried it as a Macro and as an Action
Same thing .. if I leave System.DeviceAttached in the tree .. it runs 3 times. If I disable System.DeviceAttached it doesn't run at all.

I know I'm doing something wrong but as I said .. I'm completely new to this program so I guess I don't know where to put the things you are telling me I need to do.


**just a note here ... the code pasted here is not what I pasted .. have no idea why it "word wraps" so the code here isn't showing exactly like what is in my file. Some of the lines are wrapped showing extra lines even tho they are on one line
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: problem with Start Application macro running twice

Post by kgschlosser »

you did correctly. the only way the code could run 3 times is if 3 events trigger that script to run. i would need a copy of your tree file to see what exactly is going on.

and maybe a screen shot of eventghost when the macro runs.
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: problem with Start Application macro running twice

Post by kgschlosser »

ok never mind that i got the tree from the xml you posted.,


here is what we do.

i am going to paste some xml code in here. you will want to copy all of the code and then right click on the tree in eventghost and paste it in there. it will create the needed action and scriptfile.

the reason it's running 3 times is because you have the ccRescan action in the macro along with the script. the script makes the call to run the ccRescan so the action is not needed.


but here is the code

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1710">
    <Folder Name="ccRescan" Expanded="True">
        <Macro Name="ccRescan: Checking Device">
            <Event Name="System.DeviceAttached" />
            <Action Name="ccRescan: Python Script">
                EventGhost.PythonScript(u"DEVICE =  '\\\\\\\\?\\\\HID#VID_0BEF&PID_0004&MI_05#7&3a826eb7&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}'\n\nif eg.event.payload[0] == DEVICE:\n    eg.plugins.System.Execute(u'C:\\\\Program Files (x86)\\\\CallClerk\\\\ccRescan.exe', u'', 3, True, 2, u'C:\\\\Program Files (x86)\\\\CallClerk', False, False, u'', False, False, False, False)")
            </Action>
        </Macro>
    </Folder>
</EventGhost>

let me know if this works for you. and also the only things that should really be in autostart are plugins. you can put other things in there as well but there is an event that is triggered when EG runs it's called Main.OnInit you can use that event to trigger an action instead of putting it in the autostart.

if there is anything you do not understand please feel free to ask. i am glad to help out as much as possible.

EG can be very daunting if you are new to it. but once you get the basic idea and start having it automate things for ya you will get hooked into it and want to know what else you can have it do. so don't give up. fell free to PM me i pop in here all the time. and will usually respond within 24 hours but most times within 2-3


K
If you like the work I have been doing then feel free to Image
JohnOrion
Posts: 3
Joined: Wed Aug 10, 2016 4:37 pm

Re: problem with Start Application macro running twice

Post by JohnOrion »

Ok .. that worked .. and now that I see it pasted in I see what I did wrong. Since this was the first time I used the program I guess I was not really aware of the "format" and I guess I should have paid more attention to the "built-in" examples it came with... I will take note of it next time I attempt to make something like this... I appreciate the help.

Sorry it takes so long for the replies but I'm still censored .. lol ... so I have to wait to be "approved" :D or i guess not .. this one went right though :D

Thanks again so much .. EventGhost solved my issues .... and you solved my lack on knowledge :D
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: problem with Start Application macro running twice

Post by kgschlosser »

het at one point i had lack of knowledge also, and the only way to learn is to try it out and ask questions if ya get stuck. EventGhost can be frustrating at times but when you get something to work it makes you feel really good. you were so close to having it right. and sometimes another set of exes on the problem or a simple word someone says will tell you what is it that needs to be done. i have only been using EG for about a year and a half now, and it has been a very long and hard process to learn it. and i said to myself i do not want this to happen to others. so i make it a personal point to try and help. at the very least even if i do not solve the issue there is some knowledge passed along,


K
If you like the work I have been doing then feel free to Image
Post Reply