Stop App / Start another App after event

If you have a question or need help, this is the place to be.

Stop App / Start another App after event

Postby GBWebmaster » Sat Jul 02, 2011 7:09 pm

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
GBWebmaster
Experienced User
 
Posts: 109
Joined: Wed Sep 24, 2008 5:34 am

Re: Stop App / Start another App after event

Postby jinxdone » Sat Jul 02, 2011 7:38 pm

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
jinxdone
Plugin Developer
 
Posts: 443
Joined: Tue Jan 02, 2007 4:08 pm

Re: Stop App / Start another App after event

Postby GBWebmaster » Sat Jul 02, 2011 10:31 pm

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: 109
Joined: Wed Sep 24, 2008 5:34 am

Re: Stop App / Start another App after event

Postby GBWebmaster » Mon Jul 04, 2011 8:39 am

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
GBWebmaster
Experienced User
 
Posts: 109
Joined: Wed Sep 24, 2008 5:34 am

Re: Stop App / Start another App after event

Postby Pako » Mon Jul 04, 2011 10:14 am

Maybe this is the way:
PowerDVD_Play.gif
PowerDVD_Play.gif (5.33 KiB) Viewed 1739 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: 1282
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic

Re: Stop App / Start another App after event

Postby Pako » Mon Jul 04, 2011 10:28 am

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 1736 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
Pako
Plugin Developer
 
Posts: 1282
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic

Re: Stop App / Start another App after event

Postby GBWebmaster » Mon Jul 04, 2011 1:18 pm

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
GBWebmaster
Experienced User
 
Posts: 109
Joined: Wed Sep 24, 2008 5:34 am

Re: Stop App / Start another App after event

Postby Pako » Mon Jul 04, 2011 1:56 pm

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
Pako
Plugin Developer
 
Posts: 1282
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic

Re: Stop App / Start another App after event

Postby GBWebmaster » Mon Jul 04, 2011 3:25 pm

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
GBWebmaster
Experienced User
 
Posts: 109
Joined: Wed Sep 24, 2008 5:34 am

Re: Stop App / Start another App after event

Postby Pako » Tue Jul 05, 2011 6:18 am

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
Pako
Plugin Developer
 
Posts: 1282
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic

Re: Stop App / Start another App after event

Postby GBWebmaster » Tue Jul 05, 2011 7:32 am

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
GBWebmaster
Experienced User
 
Posts: 109
Joined: Wed Sep 24, 2008 5:34 am

Re: Stop App / Start another App after event

Postby Pako » Tue Jul 05, 2011 9:57 am

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
Pako
Plugin Developer
 
Posts: 1282
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic

Re: Stop App / Start another App after event

Postby GBWebmaster » Tue Jul 05, 2011 11:43 am

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 &lt; 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
GBWebmaster
Experienced User
 
Posts: 109
Joined: Wed Sep 24, 2008 5:34 am

Re: Stop App / Start another App after event

Postby Pako » Tue Jul 05, 2011 12:25 pm

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 1696 times
Note: It is possible that you can delete the first command Play (line eg.SendKeys(hwnds[0], '{Return}'))

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

Re: Stop App / Start another App after event

Postby GBWebmaster » Tue Jul 05, 2011 12:58 pm

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.
User avatar
GBWebmaster
Experienced User
 
Posts: 109
Joined: Wed Sep 24, 2008 5:34 am


Return to General Support

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests