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.
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.
New drive notification
New drive notification
Hi,
I've been using EG for a while now and it just runs perfectly. Here's a few questions I had while trying to add more automation to my PC:
- When I insert a CD I get a System.DriveMounted event, and similarly when the CD is ejected I get a System.DriveRemoved event. Great! However, when I attach a USB mass storage device (which creates a new drive), there is no such event. I thought there used to be one in a previous EG release but I may be wrong. In any case, is it possible to get notified when a removable drive is added or removed (including the drive letter like the DriveMounted/DriveRemoved events)?
- How can I get in Python the volume name of a drive that was inserted? I'd like to trigger different actions based on the device that was inserted and was thinking of using the volume name of the mounted drive to make the distinction. I could use the drive letter but that's not very robust (for example, I have a memory card that can be inserted directly in a usb port or mounted through a card reader, and that leads to a different drive letter still I want to trigger the same event).
As a side note: I am interested in an event that is triggered when the PC comes back from resume. Fortunately I'm using an X10 remote which triggers a X10.DeviceStart event that is perfect for my needs. However, I imaging non-X10 users may also be interested in this event so it might be useful to add this type of notification natively to EG?
Thanks.
_tma_
I've been using EG for a while now and it just runs perfectly. Here's a few questions I had while trying to add more automation to my PC:
- When I insert a CD I get a System.DriveMounted event, and similarly when the CD is ejected I get a System.DriveRemoved event. Great! However, when I attach a USB mass storage device (which creates a new drive), there is no such event. I thought there used to be one in a previous EG release but I may be wrong. In any case, is it possible to get notified when a removable drive is added or removed (including the drive letter like the DriveMounted/DriveRemoved events)?
- How can I get in Python the volume name of a drive that was inserted? I'd like to trigger different actions based on the device that was inserted and was thinking of using the volume name of the mounted drive to make the distinction. I could use the drive letter but that's not very robust (for example, I have a memory card that can be inserted directly in a usb port or mounted through a card reader, and that leads to a different drive letter still I want to trigger the same event).
As a side note: I am interested in an event that is triggered when the PC comes back from resume. Fortunately I'm using an X10 remote which triggers a X10.DeviceStart event that is perfect for my needs. However, I imaging non-X10 users may also be interested in this event so it might be useful to add this type of notification natively to EG?
Thanks.
_tma_
- Bitmonster
- Site Admin
- Posts: 2239
- Joined: Mon Feb 06, 2006 10:28 pm
I really want to implement this for USB-drives, but it is not as easy as it was on first sight. The mechanism for drive notifications is completely different from the media-change notification. Another problem you already mentioned: different drives can get the same drive letter. The volume name is also not the right way, because different drives can also have the same volume name or if you don't have assigned a volume name (the default for new drives) there is also no distinction. The only real solution would be to use the drives GUID. This is constant after the drive was attached the first time. But here the coding gets really complicated and I have deferred this. But it is on my todo list.
Side note:
So actually the event should be named MediaInserted/MediaRemoved and not DriveMounted/DriveRemoved currently.
How to get the volume name from a drive letter I will post later as a small script.
Standby/resume notification is also on the todo list.
Side note:
So actually the event should be named MediaInserted/MediaRemoved and not DriveMounted/DriveRemoved currently.
How to get the volume name from a drive letter I will post later as a small script.
Standby/resume notification is also on the todo list.
Last edited by Bitmonster on Sat Jul 22, 2006 11:54 am, edited 1 time in total.
OK, thanks a lot for the quick feedback as usual 
I have been looking for this ability for a long time and the best solution I could find was based on the USBAgent program, see http://withopf.com/tools/usbagent/ Don't know if source code is available or if the developer is willing to share it with you.
Given that I'll have to use some non-EG mechanism for now, I've been experimenting with the following usbagent.inf file:
[usbagent]
ON="D:\Program Files\EventGhost\eventghost.exe" -e USBAgent.DriveMounted.%basepath%
OFF="D:\Program Files\EventGhost\eventghost.exe" -e USBAgent.DriveRemoved.%basepath%
This triggers in EG the event "Main.USBAgent.DriveMounted.F:\" when I insert a device that gets drive letter F, and the corresponding DriveRemoved event when the device is removed. So this may already be useful for some people.
In my case I actually want to act on any DriveMounted event and take the actual drive letter as a parameter in my macro. Three ways I could think of are
1) events with parameters, so I'd trigger the DriveMounted event and pass in the drive letter as parameter that I would be able to retrieve from within an EG action/macro/script somehow
2) the ability to run a macro on a partial match of an event and being able to retrieve the part that was not matched, so I would have a "partial event" USBAgent.DriveMounted that would run my macro and in the macro I would retrieve the rest of the event, being ".F:\" in this case (or without the . of course).
3) Have the same macro triggered by multiple events (basically all possible drive letters that could be mounted), then from within the action retrieve the actual event that triggered the action (from which the drive letter can be parsed out).
Any of this possible with EG currently?
Thanks.
_tma_
I have been looking for this ability for a long time and the best solution I could find was based on the USBAgent program, see http://withopf.com/tools/usbagent/ Don't know if source code is available or if the developer is willing to share it with you.
Given that I'll have to use some non-EG mechanism for now, I've been experimenting with the following usbagent.inf file:
[usbagent]
ON="D:\Program Files\EventGhost\eventghost.exe" -e USBAgent.DriveMounted.%basepath%
OFF="D:\Program Files\EventGhost\eventghost.exe" -e USBAgent.DriveRemoved.%basepath%
This triggers in EG the event "Main.USBAgent.DriveMounted.F:\" when I insert a device that gets drive letter F, and the corresponding DriveRemoved event when the device is removed. So this may already be useful for some people.
In my case I actually want to act on any DriveMounted event and take the actual drive letter as a parameter in my macro. Three ways I could think of are
1) events with parameters, so I'd trigger the DriveMounted event and pass in the drive letter as parameter that I would be able to retrieve from within an EG action/macro/script somehow
2) the ability to run a macro on a partial match of an event and being able to retrieve the part that was not matched, so I would have a "partial event" USBAgent.DriveMounted that would run my macro and in the macro I would retrieve the rest of the event, being ".F:\" in this case (or without the . of course).
3) Have the same macro triggered by multiple events (basically all possible drive letters that could be mounted), then from within the action retrieve the actual event that triggered the action (from which the drive letter can be parsed out).
Any of this possible with EG currently?
Thanks.
_tma_
- Bitmonster
- Site Admin
- Posts: 2239
- Joined: Mon Feb 06, 2006 10:28 pm
- Bitmonster
- Site Admin
- Posts: 2239
- Joined: Mon Feb 06, 2006 10:28 pm
I have just uploaded a new test version (build 624):
http://www.eventghost.org/forum/viewtopic.php?t=86
This has the following changes:
- it should give a mounted/dismounted event for every drive that has a drive letter.
- it generates the events "System.Suspend" and "System.Resume" if you go into standby and back.
- you can give "payloads" to the -e commandline option. Something like this:
EventGhost.exe -e MyEvent FirstPayload SecondPayload
will produce an event named "Main.MyEvent" with the payload as Python list:
["FirstPayload", "SecondPayload"]
that you can use in scripts.
How to access payload variables of an event is documented here:
http://www.eventghost.org/wiki/Scripting
under eg.event
To get the volume label of a drive (C:\ here) you can use something like this:
Keep in mind, that you have to escape backslashes in Python with double backslashes.
http://www.eventghost.org/forum/viewtopic.php?t=86
This has the following changes:
- it should give a mounted/dismounted event for every drive that has a drive letter.
- it generates the events "System.Suspend" and "System.Resume" if you go into standby and back.
- you can give "payloads" to the -e commandline option. Something like this:
EventGhost.exe -e MyEvent FirstPayload SecondPayload
will produce an event named "Main.MyEvent" with the payload as Python list:
["FirstPayload", "SecondPayload"]
that you can use in scripts.
How to access payload variables of an event is documented here:
http://www.eventghost.org/wiki/Scripting
under eg.event
To get the volume label of a drive (C:\ here) you can use something like this:
Code: Select all
import win32api
print win32api.GetVolumeInformation("C:\\")[0]Great! Thanks for the incredible support!
Some feedback on this build:
- The event payload thing works like a charm and is 100% useful. Thanks a lot!
- Somehow I don't get the mounted/unmounted events for the USB devices I insert/remove. Can't give you much more feedback on this one. Can I run in a debug mode or something?
- The suspend/resume events do get triggered. There seems to be something wrong with the timing however. Here's what happened when I suspended my PC at 1.55 and resumed it at 1.56:
1:55:11 Main.SuspendEvent ()
1:56:12 System.Suspend
1:56:12 X10.DeviceStart
1:56:13 Main.WakeupEvent ()
1:57:28 System.Resume
The Main.SuspendEvent and Main.WakeupEvent are the external triggers for the test. The associated action in EG for the SuspendEvent is to suspend the system. What you can see is that the System.Suspend event comes in immediately after the PC comes back from suspend so I guess the pc went in suspend mode before EG could dispatch the event. The X10.DeviceStart event is the one I have been using to detect resumes. What is funny is that the System.Resume doesn't come right away. In fact at system resume the screen stays in its own standby mode until I press a key. The System.Resume event in EG happens at that time...
Let me know if I can help in some way. In any case the event payload support allows me to do what I wanted (currently through the usb agent) so thanks a lot.
_tma_
Some feedback on this build:
- The event payload thing works like a charm and is 100% useful. Thanks a lot!
- Somehow I don't get the mounted/unmounted events for the USB devices I insert/remove. Can't give you much more feedback on this one. Can I run in a debug mode or something?
- The suspend/resume events do get triggered. There seems to be something wrong with the timing however. Here's what happened when I suspended my PC at 1.55 and resumed it at 1.56:
1:55:11 Main.SuspendEvent ()
1:56:12 System.Suspend
1:56:12 X10.DeviceStart
1:56:13 Main.WakeupEvent ()
1:57:28 System.Resume
The Main.SuspendEvent and Main.WakeupEvent are the external triggers for the test. The associated action in EG for the SuspendEvent is to suspend the system. What you can see is that the System.Suspend event comes in immediately after the PC comes back from suspend so I guess the pc went in suspend mode before EG could dispatch the event. The X10.DeviceStart event is the one I have been using to detect resumes. What is funny is that the System.Resume doesn't come right away. In fact at system resume the screen stays in its own standby mode until I press a key. The System.Resume event in EG happens at that time...
Let me know if I can help in some way. In any case the event payload support allows me to do what I wanted (currently through the usb agent) so thanks a lot.
_tma_
- Bitmonster
- Site Admin
- Posts: 2239
- Joined: Mon Feb 06, 2006 10:28 pm
What kind of USB drive do you have? Is this a normal external USB-HDD?
There might be the problem that the logger is showing an event a bit later. The mechanism is that the EG notices the event and informs another thread (the action thread) of it and waits for this thread to execute any macro that might match the event. Simultaneous it sends the event to the logger to show it, but the logger is also a thread of its own. So if there is no macro that matches, EG will let Windows go into standby very fast and the logger might not have the time to show it before Windows does go into standby.
To check this you can make a macro with a PlaySound action (with wait option enabled) for the System.Suspend event, so that this would delay going to standby for a moment.
For System.Resume I'm not sure what is happening on your machine. Does this "screen stays in its own standby mode" happen regardless if EG is running or not? If my machine resumes, it goes directly to the login screen, because I have configured some more users.
There might be the problem that the logger is showing an event a bit later. The mechanism is that the EG notices the event and informs another thread (the action thread) of it and waits for this thread to execute any macro that might match the event. Simultaneous it sends the event to the logger to show it, but the logger is also a thread of its own. So if there is no macro that matches, EG will let Windows go into standby very fast and the logger might not have the time to show it before Windows does go into standby.
To check this you can make a macro with a PlaySound action (with wait option enabled) for the System.Suspend event, so that this would delay going to standby for a moment.
For System.Resume I'm not sure what is happening on your machine. Does this "screen stays in its own standby mode" happen regardless if EG is running or not? If my machine resumes, it goes directly to the login screen, because I have configured some more users.
As far as I know I tried with standard usb mass storage devices: once with a garmin nuvi gps system which has two drives associated, and I also tried with a sandisk ultra ii plus memory card that you can insert directly in a usb port. I admin these are not really standard hard disks but they do manifest themselves just like a hd.
As for the suspend event: I'll try your suggestion, haven't had time yet.
About the resume event: the logs from my previous post were about an automatic, scheduled resume. Today I resumed the system by pressing the power button and then the screen comes up right away and so does the resume event in EG.
In fact the more I think about it, the more I like the current behavior. I was looking for a way to distinguish a scheduled resume from a manual resume, because on a manual resume I want my audio jukebox app to start playing while this is not needed on a scheduled resume at night (it's even not desired, suppose I forgot to turn off the amp and left it at high volume
. The way the resume works now I could easily start playing music on the resume event, indicating a manual resume or a user action after an automated resume.
_tma_
As for the suspend event: I'll try your suggestion, haven't had time yet.
About the resume event: the logs from my previous post were about an automatic, scheduled resume. Today I resumed the system by pressing the power button and then the screen comes up right away and so does the resume event in EG.
In fact the more I think about it, the more I like the current behavior. I was looking for a way to distinguish a scheduled resume from a manual resume, because on a manual resume I want my audio jukebox app to start playing while this is not needed on a scheduled resume at night (it's even not desired, suppose I forgot to turn off the amp and left it at high volume
_tma_
- Bitmonster
- Site Admin
- Posts: 2239
- Joined: Mon Feb 06, 2006 10:28 pm
Here some results/answers:
- The suspend event comes in time when I suspend the PC using the power button. When I suspend the PC in an automated way (through EG's suspend action) the event comes at resume time. I tried as you suggested with a playsound action, and I hear the sound first thing when the pc is resumed. When I press the power switch to suspend the system, I do hear the sound before the system suspends.
- The drives are only present when the devices are plugged in, they disappear when I unplug them. When I plug them in, windows starts the "Safely remove hardware" application (system tray) that you can use to unplug the device again. When I use this app to "Safely remove USB Mass Storage Device - Drive F" the drive disappears (no drive letter). I just tried with a real external hard disk and I get the same behavior. FYI I'm running windows XP professional SP2.
Hope this helps.
_tma_
- The suspend event comes in time when I suspend the PC using the power button. When I suspend the PC in an automated way (through EG's suspend action) the event comes at resume time. I tried as you suggested with a playsound action, and I hear the sound first thing when the pc is resumed. When I press the power switch to suspend the system, I do hear the sound before the system suspends.
- The drives are only present when the devices are plugged in, they disappear when I unplug them. When I plug them in, windows starts the "Safely remove hardware" application (system tray) that you can use to unplug the device again. When I use this app to "Safely remove USB Mass Storage Device - Drive F" the drive disappears (no drive letter). I just tried with a real external hard disk and I get the same behavior. FYI I'm running windows XP professional SP2.
Hope this helps.
_tma_
- Bitmonster
- Site Admin
- Posts: 2239
- Joined: Mon Feb 06, 2006 10:28 pm
- Bitmonster
- Site Admin
- Posts: 2239
- Joined: Mon Feb 06, 2006 10:28 pm