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.

Stop App / Start another App after event

If you have a question or need help, this is the place to be.
Post Reply
User avatar
GBWebmaster
Experienced User
Posts: 115
Joined: Wed Sep 24, 2008 5:34 am

Stop App / Start another App after event

Post by GBWebmaster »

Hello Community,

I have opened a topic in the German forum, but nobody could help me.

The following szenario:
When I mount a dvd or a iso-image (Event: "System.DriveMounted.H"), EG should check, if a application like dvbviewer runs this time. And, if so, EG should close dvbviewer and start PowerDVD. After remove of the dvd or the iso-image, EG should close PowerDVD and start dvbviewer. If no app runs, EG should only start PowerDVD.

Is this possible?
Thanks for all advices.

GBWebmaster
F├╝r den, der nie das Rudel anf├╝hrt,
wird sich die Aussicht nicht ändern.
User avatar
jinxdone
Plugin Developer
Posts: 443
Joined: Tue Jan 02, 2007 4:08 pm

Re: Stop App / Start another App after event

Post by jinxdone »

Maybe something like this will do the trick? (copy&paste into EG)

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1397">
    <Folder Name="Disk Insert/Remove" Expanded="True">
        <Macro Name="Disk inserted">
            <Event Name="System.DriveMounted.H" />
            <Action>
                Window.FindWindow(u'dvbviewer.exe', None, None, None, None, None, False, 0.0, 2)
            </Action>
            <Action>
                EventGhost.NewJumpIf(XmlIdLink(825), 0, True)
            </Action>
            <Action>
                System.Execute(u'C:\\Program Files (x86)\\PowerDVD\\powerdvd.exe', u'', 0, False, 2, u'')
            </Action>
        </Macro>
        <Macro Name="Disk Removed">
            <Event Name="System.DriveRemoved.H" />
            <Action>
                Window.FindWindow(u'powerdvd.exe', None, None, None, None, None, False, 0.0, 2)
            </Action>
            <Action>
                EventGhost.NewJumpIf(XmlIdLink(838), 0, True)
            </Action>
            <Action>
                System.Execute(u'C:\\Program Files (x86)\\DVBViewer\\dvbviewer.exe', u'', 0, False, 2, u'')
            </Action>
        </Macro>
        <Macro Name="DVBViewer: Exit" id="825">
            <Action>
                Window.FindWindow(u'dvbviewer.exe', None, None, None, None, None, False, 0.0, 0)
            </Action>
            <Action>
                Window.Close()
            </Action>
        </Macro>
        <Macro Name="PowerDVD: Exit" id="838">
            <Action>
                Window.FindWindow(u'powerdvd.exe', None, None, None, None, None, False, 0.0, 0)
            </Action>
            <Action>
                Window.Close()
            </Action>
        </Macro>
    </Folder>
</EventGhost>
Change all the paths of the programs to correspond with your setup. I didn't test if it works or not.. :) If it doesnt work right out of the box tinker about with the macros, you should be able to see the idea how it can be done.
User avatar
GBWebmaster
Experienced User
Posts: 115
Joined: Wed Sep 24, 2008 5:34 am

Re: Stop App / Start another App after event

Post by GBWebmaster »

Great, it works.
Thank you very much.

GBWebmaster
F├╝r den, der nie das Rudel anf├╝hrt,
wird sich die Aussicht nicht ändern.
User avatar
GBWebmaster
Experienced User
Posts: 115
Joined: Wed Sep 24, 2008 5:34 am

Re: Stop App / Start another App after event

Post by GBWebmaster »

One more question, sorry.
Is there a chance to start the movie playback in PowerDVD automatically. At the present time I must press the "Play-Button" to start the movie in PowerDVD.

GBWebmaster
F├╝r den, der nie das Rudel anf├╝hrt,
wird sich die Aussicht nicht ändern.
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Stop App / Start another App after event

Post by Pako »

Maybe this is the way:
PowerDVD_Play.gif
PowerDVD_Play.gif (5.33 KiB) Viewed 8635 times
Python script:

Code: Select all

from time import sleep
findPowerDVD = eg.WindowMatcher('PowerDVD{*}.exe', 'CyberLink PowerDVD{*}')
hwnds = []
while not hwnds:
    hwnds = findPowerDVD()
    sleep(0.1)
I didn't test if it works or not ...

Pako
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Stop App / Start another App after event

Post by Pako »

I realized the need to do some insurance in case that PowerDVD will not start:
PowerDVD_Play.gif
PowerDVD_Play.gif (4.79 KiB) Viewed 8632 times
Python script:

Code: Select all

from time import sleep
findPowerDVD = eg.WindowMatcher('PowerDVD{*}.exe', 'CyberLink PowerDVD{*}')
hwnds = []
i = 0
while not hwnds:
    hwnds = findPowerDVD()
    sleep(0.1)
    i += 1
    if i == 200:
        break
if i < 200:
    eg.SendKeys(hwnds[0], '{Return}')
else:
    print "Cyberlink PowerDVD not found"
I didn't test if it works or not ...

Pako
User avatar
GBWebmaster
Experienced User
Posts: 115
Joined: Wed Sep 24, 2008 5:34 am

Re: Stop App / Start another App after event

Post by GBWebmaster »

Hello Pako,

after insert the scriptcode, I get the following errors:

Code: Select all

15:09:25   Error compiling script.
15:09:25   Traceback (most recent call last):
15:09:25   IndentationError: unexpected indent (1, line 1)
Is it a problem, that I work with the PowerDVDCinema10.exe under "C:\Program Files (x86)\CyberLink\PowerDVD10\PowerDVD Cinema\PowerDVDCinema10.exe"?

GBWebmaster
F├╝r den, der nie das Rudel anf├╝hrt,
wird sich die Aussicht nicht ändern.
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Stop App / Start another App after event

Post by Pako »

GBWebmaster wrote:

Code: Select all

15:09:25   IndentationError: unexpected indent (1, line 1)
Is it a problem, that I work with the PowerDVDCinema10.exe under "C:\Program Files (x86)\CyberLink\PowerDVD10\PowerDVD Cinema\PowerDVDCinema10.exe"?
No, check line 1 of your script and you will see that you have a improper indentation of your code.

Pako
User avatar
GBWebmaster
Experienced User
Posts: 115
Joined: Wed Sep 24, 2008 5:34 am

Re: Stop App / Start another App after event

Post by GBWebmaster »

Sorry, my mistake. Copy & Paste was no good idea ... ;)
Now it works.

I have a favor to ask you. Could you tell me, what the script does?
F├╝r den, der nie das Rudel anf├╝hrt,
wird sich die Aussicht nicht ändern.
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Stop App / Start another App after event

Post by Pako »

GBWebmaster wrote:I have a favor to ask you. Could you tell me, what the script does?
Of course I can.
The script tries (every 100ms), if it can find a window of PowerDVD.
Once the window is found, the script sends (to the found window) the command Play and ends.
If the window is not found within 20 seconds, the script ends.

Pako
User avatar
GBWebmaster
Experienced User
Posts: 115
Joined: Wed Sep 24, 2008 5:34 am

Re: Stop App / Start another App after event

Post by GBWebmaster »

Thank you, Pako.

I have a bit of a problem with PowerDVDCinema. With your script, every movie resume playback from the last scene.
What must be changed to play movies always from the beginning? Is this possible?


GBWebmaster
F├╝r den, der nie das Rudel anf├╝hrt,
wird sich die Aussicht nicht ändern.
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Stop App / Start another App after event

Post by Pako »

I do not know.
I do not use PowerDVD.
Perhaps this modification could help:

Code: Select all

from time import sleep
findPowerDVD = eg.WindowMatcher('PowerDVD{*}.exe', 'CyberLink PowerDVD{*}')
hwnds = []
i = 0
while not hwnds:
    hwnds = findPowerDVD()
    sleep(0.1)
    i += 1
    if i == 200:
        break
if i < 200:
    eg.SendKeys(hwnds[0], 's')
    sleep(0.1)
    eg.SendKeys(hwnds[0], '{Return}')
else:
    print "Cyberlink PowerDVD not found"
Note: 's' is PowerDVD command Stop.

It may also be that your PowerDVD program uses a different keypresses to control.
Pako
User avatar
GBWebmaster
Experienced User
Posts: 115
Joined: Wed Sep 24, 2008 5:34 am

Re: Stop App / Start another App after event

Post by GBWebmaster »

Hello Pako,
the additional scriptcode doesn't change anything.

But when I add the action "CyberLink PowerDVD: Navigation Down" and "CyberLink PowerDVD: Play" after your script, then it works.
Could I add the step "Navigation Down" into the script?

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1534">
    <Macro Name="Laden einer ISO-Datei" Expanded="True">
        <Event Name="System.DriveMounted.H" />
        <Action>
            Window.FindWindow(u'dvbviewer.exe', None, None, None, None, None, False, 0.0, 2)
        </Action>
        <Action>
            EventGhost.NewJumpIf(XmlIdLink(1418), 0, True)
        </Action>
        <Action>
            System.Execute(u'C:\\Program Files (x86)\\CyberLink\\PowerDVD10\\PowerDVD Cinema\\PowerDVDCinema10.exe', u'', 0, False, 2, u'')
        </Action>
        <Action>
            EventGhost.PythonScript(u'from time import sleep\nfindPowerDVD = eg.WindowMatcher(\'PowerDVD{*}.exe\', \'CyberLink PowerDVD{*}\')\nhwnds = []\ni = 0\nwhile not hwnds:\n    hwnds = findPowerDVD()\n    sleep(0.1)\n    i += 1\n    if i == 200:\n        break\nif i < 200:\n    eg.SendKeys(hwnds[0], \'{Return}\')\nelse:\n    print "Cyberlink PowerDVD not found"')
        </Action>
        <Action>
            PowerDvd.NavigationDown()
        </Action>
        <Action>
            PowerDvd.Play()
        </Action>
    </Macro>
</EventGhost>
GBWebmaster
F├╝r den, der nie das Rudel anf├╝hrt,
wird sich die Aussicht nicht ändern.
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Stop App / Start another App after event

Post by Pako »

GBWebmaster wrote:Could I add the step "Navigation Down" into the script?
As I understand it, so now it works as follows:
1. The script waits at the window of PowerDVD and then sends a command to Play
2. Then follow action CyberLink PowerDVD: Navigation Down
3. Then follow action CyberLink PowerDVD: Play

If so, then you can modify the Python Script as follows:

Code: Select all

from time import sleep
findPowerDVD = eg.WindowMatcher('PowerDVD{*}.exe', 'CyberLink PowerDVD{*}')
hwnds = []
i = 0
while not hwnds:
    hwnds = findPowerDVD()
    sleep(0.1)
    i += 1
    if i == 200:
        break
if i < 200:
    eg.SendKeys(hwnds[0], '{Return}')
    eg.SendKeys(hwnds[0], '{Down}')
    eg.SendKeys(hwnds[0], '{Return}')
else:
    print "Cyberlink PowerDVD not found"
and macro looks like this:
PowerDVD_Play2.gif
PowerDVD_Play2.gif (4.41 KiB) Viewed 8592 times
Note: It is possible that you can delete the first command Play (line eg.SendKeys(hwnds[0], '{Return}'))

Pako
User avatar
GBWebmaster
Experienced User
Posts: 115
Joined: Wed Sep 24, 2008 5:34 am

Re: Stop App / Start another App after event

Post by GBWebmaster »

Hello Pako,
thank you very, very much. Now it works great, really.
Pako wrote:Note: It is possible that you can delete the first command Play (line eg.SendKeys(hwnds[0], '{Return}'))
Yes, it is possible. The first line isn't necessary.
F├╝r den, der nie das Rudel anf├╝hrt,
wird sich die Aussicht nicht ändern.
Post Reply