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.

Help triggering macro w/ plugging in specific USB device

If you have a question or need help, this is the place to be.
Post Reply
nexgen91
Posts: 2
Joined: Sun Dec 29, 2013 3:44 am

Help triggering macro w/ plugging in specific USB device

Post by nexgen91 »

I am trying to trigger an even when I plug in my phone to my computer, I can use System.DeviceAttached but that will activate it when any USB device is attached. Is there a way to isolate the trigger to only the one device? I saw a write up on using python to do this here: http://www.eventghost.org/forum/viewtop ... f=2&t=2883
but am having a hard time understanding how to do said actions as I am really new to this program and python. Can someone please break it down for me so I know what to do and how to format the code/events, etc?
I have tried using the following event, but it does not seem to be working...

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1640">
<Event Name="DeviceRemoved.\\?\USB#VID_04E8&amp;PID_6860#42f70c04ffeeaffb#{a5dcbf10-6530-11d2-901f-00c04fb951ed}" />
</EventGhost>

Thank you
kkl
Experienced User
Posts: 317
Joined: Wed May 04, 2011 9:32 pm

Re: Help triggering macro w/ plugging in specific USB device

Post by kkl »

The link you found is an excellent one, something I wished I had learned earlier. As usual, what is trivial for Pako is a bit mysterious to some of us. The key point is that his python command generates another event when the device is attached, an event that is specific to that device. So, you actually need two macros; the first receives the System.DeviceAttached event that then generates a new event that can act as a trigger in another macro. Example configuration:
eg1.JPG
Here's the log pane:
eg2.JPG
The "DeviceAttached.VID_22B8&PID_2E62" event was created by the "eg.TriggerEvent(eg.event.payload[0][8:25], prefix = eg.event.suffix)" python command.
kkl
Experienced User
Posts: 317
Joined: Wed May 04, 2011 9:32 pm

Re: Help triggering macro w/ plugging in specific USB device

Post by kkl »

And here's a simpler method as suggested by sem;colon in this thread:
eg3.JPG
nexgen91
Posts: 2
Joined: Sun Dec 29, 2013 3:44 am

Re: Help triggering macro w/ plugging in specific USB device

Post by nexgen91 »

Ok now this is awsome, I finally got it working. Now when I plug my phone into my computer it opens AirDroid (remote control for phone) on my phone and then calls up the web interface in a seperate Chrome window. Once I unplugg the phone it closes both instances of AirDroid :) Success feels great

Thank you for your help
NMGMarques
Posts: 3
Joined: Thu Jun 11, 2015 11:04 am

Re: Help triggering macro w/ plugging in specific USB device

Post by NMGMarques »

That went over my head so fast it felt like I was watching a fighter jet go by.

Considering I want the device in this line to run the macro:
System.DeviceAttached [u'\\\\?\\HID#{00001812-0000-1000-8000-00805f9b34fb}_Dev_VID&02045e_PID&07c5_REV&0001_ca713c8ae6ee#9&10e061c8&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}']

I tried this:

Image

But naturally only got this:

Image

Probably because I have no freaking clue what I am doing :)
Sem;colon
Plugin Developer
Posts: 625
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Help triggering macro w/ plugging in specific USB device

Post by Sem;colon »

Hello NMGMarques,

can you please paste the code from your python command?
If you like my work, Image me a drink :wink:
NMGMarques
Posts: 3
Joined: Thu Jun 11, 2015 11:04 am

Re: Help triggering macro w/ plugging in specific USB device

Post by NMGMarques »

Sem;colon wrote:Hello NMGMarques,

can you please paste the code from your python command?
You see! Right there. That's what I'm talking about when I say I have no freakin' idea what I'm doing :)

You mean I have to have python installed on Windows? If so, is there another way to trigger the event on specific device, without going the python route? If not, then could you please be a bit more specific since I am totally lost :shock:

I reverted back to
Image http://i.imgur.com/M03Sx2w.png
which works, but each time I undock and redock my Surface, it detects some 10 devices and opens OneNote as many times.

edit: imgur doesn't seem to be working for me right now. Link pasted above.
Javier
Experienced User
Posts: 73
Joined: Sun Dec 01, 2013 3:45 pm

Re: Help triggering macro w/ plugging in specific USB device

Post by Javier »

Copy and paste the following code into a folder (or anywhere in the "Configuration Tree") under "Configuration". it will trigger unique events for every device when it is attached or removed. Once you connect your device you can drag the event from the "Log" to your macro.

You do not have to install Python as EG is capable of running python code written by the user. If you would like the setup you have to work you need to double click on the "Python Command" and copy the code you wrote under "Python Statement:" so somebody can look at it and see if there is a reason it is not working.

Good Luck!

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1700">
    <Folder Name="Attached/Removed Triggers Event from Payload" Expanded="True">
        <Macro Name="Trigger Event When System.DeviceDetached">
            <Event Name="System.DeviceRemoved" />
            <Action>
                EventGhost.TriggerEvent(u'Removed {eg.event.payload[0]}', 0.0)
            </Action>
        </Macro>
        <Macro Name="Trigger Event When System.DeviceAttached">
            <Event Name="System.DeviceAttached" />
            <Action>
                EventGhost.TriggerEvent(u'Attached {eg.event.payload[0]}', 0.0)
            </Action>
        </Macro>
    </Folder>
</EventGhost>
Edit. You may want to copy and past the code from the link on the first post as some members showed that the payload may be different if devices are connected to different USB ports. I only use this for bluetooth devices so I have not encountered this problem.
Sem;colon
Plugin Developer
Posts: 625
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Help triggering macro w/ plugging in specific USB device

Post by Sem;colon »

NMGMarques wrote: You mean I have to have python installed on Windows? If so, is there another way to trigger the event on specific device, without going the python route? If not, then could you please be a bit more specific since I am totally lost :shock:
No no, it'S all good, I'm refering to the python command action in your post (the one that says "if.eg.event.payload[0]...") please do a right click and select properties, copy and paste here what is set there.
I thik there's an syntax error.
If you like my work, Image me a drink :wink:
NMGMarques
Posts: 3
Joined: Thu Jun 11, 2015 11:04 am

Re: Help triggering macro w/ plugging in specific USB device

Post by NMGMarques »

Thanks guys! That worked:
Image
Post Reply