How to automate this... - AVS Forum
Forum Jump: 
 
Thread Tools
post #1 of 22 Old 04-05-2012, 01:03 AM - Thread Starter
AVS Special Member
 
Murilo's Avatar
 
Join Date: Nov 2003
Posts: 4,679
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 7 Post(s)
Liked: 12
I have one last problem with my htpc and that is i would like when a specific program is running on my htpc for the input on my avr to be changed.

The http url to change the input on my avr is this.

http://192.168.1.9/PDA/sendMainZone....Function=HDMI2

My issue is how do i like that input change to occur when a command program starts running? So basically when the command program starts running the above http command is sent.

I looked at eventghost but im really not sure how to do this. My automation skill really only goes to programming universal remotes, but unfortunately with this i need it to switch to that input when the command program is running.
Murilo is offline  
Sponsored Links
Advertisement
 
post #2 of 22 Old 04-05-2012, 06:38 AM
Member
 
Xophile's Avatar
 
Join Date: May 2004
Posts: 30
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
Liked: 10
A couple of years ago I used a program called "Automate" a lot. See if that one might do it!
Xophile is offline  
post #3 of 22 Old 04-05-2012, 08:24 AM
AVS Special Member
 
erickotz's Avatar
 
Join Date: Feb 2003
Location: Charlotte, NC
Posts: 1,123
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
Liked: 30
Quote:
Originally Posted by Xophile View Post

A couple of years ago I used a program called "Automate" a lot. See if that one might do it!

Just hitting that URL with wget might be enough to trigger it? I'd also look into AutoIt

Quality Assurance Manager, Ceton Corporation
erickotz is offline  
post #4 of 22 Old 04-05-2012, 11:51 AM
Member
 
glorpsd's Avatar
 
Join Date: Apr 2009
Posts: 100
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
Liked: 14
You need some kind of "wrapper" to handle the network communications to port 80 on 192.168.1.9 using HTTP or whatever's in the URL. If it's as simple as navigating to that URL on a Windows platform you should be able to do it with VBScipt which will create and use an Internet Explorer" object. This code:

Code:
Set objBrowser = CreateObject("InternetExplorer.Application")

Dim URL
URL = "http://192.168.1.9/PDA/sendMainZone.asp?setAuto=Manual&listInputFunction=HDMI2"

objBrowser.Visible = 0
objBrowser.Navigate URL
WScript.Sleep (5000)
objBrowser.Quit
should launch an invisible copy of IE and tell it to "go to" that URL. You can save that code into a text editor like notepad, then save that as .vbs. From there set up EventGhost to "execute" .vbs when it receives an IR input or whatever you expect to trigger it. Since it's vbs, Windows should know what to do with it if you just execute it as if it were a program. You may have to tweak how you actually send the URL using IE though. It worked for me on a site like www.microsoft.com but I can't test your URL. When you are testing, you may want to set .Visible = 1 to see what it actually does in the browser. Also .Sleep(5000) will wait 5 seconds before it closes IE after sending the URL before it closes IE. You may need to tweak that too.

Here's documentation on the IE object methods and properties:
http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
glorpsd is online now  
post #5 of 22 Old 04-05-2012, 02:49 PM
Senior Member
 
cdru's Avatar
 
Join Date: Jul 2005
Posts: 331
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
Liked: 13
Quote:
Originally Posted by glorpsd View Post

You need some kind of "wrapper" to handle the network communications to port 80 on 192.168.1.9 using HTML or whatever's in the URL. If it's as simple as navigating to that URL on a Windows platform you should be able to do it with VBScipt which will create and use an Internet Explorer" object....

Your script probably works, but creating an IE object it's overkill. Just use XmlHttp instead.

Code:
set xmlhttp = createobject ("Microsoft.XmlHttp")
xmlhttp.open "get", $YOUR_URL, false
xmlhttp.send
XmlHttp is much lighter, plus you don't have to worry about any sleeps or delays.
cdru is offline  
post #6 of 22 Old 04-05-2012, 05:30 PM - Thread Starter
AVS Special Member
 
Murilo's Avatar
 
Join Date: Nov 2003
Posts: 4,679
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 7 Post(s)
Liked: 12
Quote:
Originally Posted by glorpsd View Post

You need some kind of "wrapper" to handle the network communications to port 80 on 192.168.1.9 using HTML or whatever's in the URL. If it's as simple as navigating to that URL on a Windows platform you should be able to do it with VBScipt which will create and use an Internet Explorer" object. This code:

Code:
Set objBrowser = CreateObject("InternetExplorer.Application")

Dim URL
URL = "http://192.168.1.9/PDA/sendMainZone.asp?setAuto=Manual&listInputFunction=HDMI2"

objBrowser.Visible = 0
objBrowser.Navigate URL
WScript.Sleep (5000)
objBrowser.Quit
should launch an invisible copy of IE and tell it to "go to" that URL. You can save that code into a text editor like notepad, then save that as .vbs. From there set up EventGhost to "execute" .vbs when it receives an IR input or whatever you expect to trigger it. Since it's vbs, Windows should know what to do with it if you just execute it as if it were a program. You may have to tweak how you actually send the URL using IE though. It worked for me on a site like www.microsoft.com but I can't test your URL. When you are testing, you may want to set .Visible = 1 to see what it actually does in the browser. Also .Sleep(5000) will wait 5 seconds before it closes IE after sending the URL before it closes IE. You may need to tweak that too.

Here's documentation on the IE object methods and properties:
http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx

Thanks for the detailed explanation. Im not very good at this, but it does infact work when i click on the vbs file manually!


Anyway eventghost is where it gets tricky, i have no experience so i opened eventghost, what do i use in eventghost to execute the vbs file?

I went to create macro then start system application, pointed it to the vbs file and i get %1 is not valid.
Murilo is offline  
post #7 of 22 Old 04-05-2012, 05:32 PM - Thread Starter
AVS Special Member
 
Murilo's Avatar
 
Join Date: Nov 2003
Posts: 4,679
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 7 Post(s)
Liked: 12
Actually just found this on the eventghost website going to give it a try. He also gets the same error %1 is not valid. The post below suggests to make the file exe file? Will that work. Im getting confused, nothing i try in event ghost seems to work.

http://www.eventghost.org/forum/view...php?f=2&t=3733

I dont understand how the solution above suggests pointing it to an .exe file when he asked about vbs, it might be over my head. But even stranger i dont get why event ghost cant even excute a .vbs file or what im doing wrong.
Murilo is offline  
post #8 of 22 Old 04-05-2012, 07:20 PM
Member
 
glorpsd's Avatar
 
Join Date: Apr 2009
Posts: 100
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
Liked: 14
Quote:
Originally Posted by Murilo View Post

But even stranger i dont get why event ghost cant even excute a .vbs file or what im doing wrong.

That's my fault. Sorry. I figured EventGhost would be able to execute a file that had a registered application extension like .vbs. It won't, so you need to be explicit about how to run it.
Configure an EventGhost macro to trigger on receiving your desired IR event. Add a System->Start Application action to that macro. In the "Executable" box of that action enter:
c:\\windows\\system32\\wscript.exe
In the "command line options" box enter:
".vbs"
The quotes above are required if your path has spaces.

That should run the script. A few other thoughts.

- Make sure this works before trying to set it all up in EventGhost. Open IE on your HTPC and enter the URL and hit enter. That should trigger the action you expect. If it doesn't this isn't going to work. You need to be able to do it the browser URL first. You should also test that the script triggers what you want outside of EventGhost. Just double-click it from explorer.
- Is all of this being done on the same PC? You're sending the event to EG and then EG triggers the script to send the URL right to that same PC? If so, you may need to use the loopback interface instead of using the machine's local IP address. Try http://127.0.0.1/... or http://localhost/... instead of http://192.168.1.9/...
- As was suggested, the IE object is resource heavy but I'd get it working/test using it, then if it all works as expected you can switch to the XMLHTTP object. You can make the IE object visible to see what it's doing which may be helpful when you are testing this.
glorpsd is online now  
post #9 of 22 Old 04-06-2012, 12:48 AM - Thread Starter
AVS Special Member
 
Murilo's Avatar
 
Join Date: Nov 2003
Posts: 4,679
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 7 Post(s)
Liked: 12
The vbs file does work. I can double click on it and it will change my avr input like it should. And yes its all being done on the same pc. And to test if this is working im just hitting the test button.


Im just a bit confused how to get it working in eventghost.

First the script gui only seems to work or appears when i dont use the second line ".vbs" ? Do i need that. When i enter the second line i get filename, syntax ect... is incorrect. When i just have c:\\windows\\system32\\wscript.exe entered, it seems to work and a window script host setting window pops up.

Anyway im still not sure how this will trigger the vbs script to switch my avr inputs.

The vbs script location is C:\\execute.vbs



Im assuming i just run the macro that executes the script, then the one to execute the vbs file should run? I am trying this and its just not doing anything. When i try this I still get %1 is not a valid win32 application when the vbs file is suppose to execute.

Thanks for your help in advance.
Murilo is offline  
post #10 of 22 Old 04-06-2012, 05:42 AM
AVS Special Member
 
StardogChampion's Avatar
 
Join Date: Dec 2007
Location: New Hampshire, USA
Posts: 3,003
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 35 Post(s)
Liked: 121
You substituted the actual path to your VBS file for ".vbs", correct?

 

 

StardogChampion is offline  
post #11 of 22 Old 04-06-2012, 07:26 AM
Member
 
glorpsd's Avatar
 
Join Date: Apr 2009
Posts: 100
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
Liked: 14
^What he said. I meant for you to substitute the path/filename of the vbs file you have saved on your computer for the part in the brackets. The "command line options" box should be:
"C:\\execute.vbs"
glorpsd is online now  
post #12 of 22 Old 04-06-2012, 09:45 AM
Member
 
glorpsd's Avatar
 
Join Date: Apr 2009
Posts: 100
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
Liked: 14
It occurred to me that you can probably do all this in a python script that EventGhost will execute directly. No need for external VBS files. All you need is an EventGhost->Python Script Action in your macro and this code as the script:

Code:
import urllib
URL = "http://192.168.1.9/PDA/sendMainZone.asp?setAuto=Manual&listInputFunction=HDMI2"
urllib.urlopen(URL)
Can't get simpler or more lightweight than that
glorpsd is online now  
post #13 of 22 Old 04-06-2012, 03:32 PM
Member
 
Tyborg's Avatar
 
Join Date: Sep 2007
Posts: 42
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 2 Post(s)
Liked: 14
You can launch from eventghost by using cscript.exe and then your vbs file as the argument. From the command line it would look like this,

cscript.exe somescript.vbs
Tyborg is offline  
post #14 of 22 Old 04-06-2012, 08:01 PM - Thread Starter
AVS Special Member
 
Murilo's Avatar
 
Join Date: Nov 2003
Posts: 4,679
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 7 Post(s)
Liked: 12
LoL my bad, my 5 day old event ghost experience is showing badly.

Thanks for the help, am going to try some of these suggestions and report back.

And thanks everyone for the help, its not easy to find people willing to help with eventghost. Alot of developers rather then support on the official forum.
Murilo is offline  
post #15 of 22 Old 04-06-2012, 08:07 PM - Thread Starter
AVS Special Member
 
Murilo's Avatar
 
Join Date: Nov 2003
Posts: 4,679
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 7 Post(s)
Liked: 12
Ok python script worked, so im just going to go with that.

Second part is how do i link this to occur when a command program is running.

I have a batch file that runs titled C:\\Xbmc\\bluray.bat, i want the input to switch when it see's this file is running? Is this posisble?

I should mention the actual batch file i have working is launched through xbmc, so i dont want it to launch in eventghost. Im just curious how do i set the circumstance for the input to switch only when it see's this batch file is running? So basically can eventghost notice or monitor when this batch file is running to trigger the input switch?
Murilo is offline  
post #16 of 22 Old 04-06-2012, 10:31 PM
Member
 
glorpsd's Avatar
 
Join Date: Apr 2009
Posts: 100
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
Liked: 14
Quote:
Originally Posted by Murilo View Post

I have a batch file that runs titled C:\\Xbmc\\bluray.bat, i want the input to switch when it see's this file is running? Is this posisble?

Uh...

If you are running a bat file just have the bat file execute the vbs script. You don't need EventGhost at all. One line of code in the bat at the appropriate place:

c:\\windows\\system32\\cscript.exe "c:\\execute.vbs"

since you already know that script works to trigger your avr, use the lightweight xmlhttp object for the vbs code.
glorpsd is online now  
post #17 of 22 Old 04-07-2012, 05:38 AM - Thread Starter
AVS Special Member
 
Murilo's Avatar
 
Join Date: Nov 2003
Posts: 4,679
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 7 Post(s)
Liked: 12
Quote:
Originally Posted by glorpsd View Post

Uh...

If you are running a bat file just have the bat file execute the vbs script. You don't need EventGhost at all. One line of code in the bat at the appropriate place:

c:\\windows\\system32\\cscript.exe "c:\\execute.vbs"

since you already know that script works to trigger your avr, use the lightweight xmlhttp object for the vbs code.

It should be mentioned i did not setup this bat file myself. It was done by someone with bat file command scripting knowledge like you guys.


Will give it a try sounds simple enough. Thanks again for the help.
Murilo is offline  
post #18 of 22 Old 04-11-2012, 05:17 AM - Thread Starter
AVS Special Member
 
Murilo's Avatar
 
Join Date: Nov 2003
Posts: 4,679
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 7 Post(s)
Liked: 12
This did not quite work because i did not explain this properly in the recent post.

The bat is a separate aspect if we can forget that, i dont need that triggered because i trigger that myself.

I basically need the input to switch if a command program is running. The command program was not created by me, but if anyone can tell me how in event ghost to make the input switch when it see's the command program running it would be greatly appreciated.

The command program is just in C:\\Xbmc\\Control.cmd

And just to reiterate, i need eventghost to somehow monitor when this program runs, to activate the input switch i got working above. I dont want event ghost to execute the command file, jut notice when its running to trigger the input switch.


Thanks in advance if anyone can help explain how i would set that up in event ghost.
Murilo is offline  
post #19 of 22 Old 04-11-2012, 06:36 AM
Senior Member
 
leewcraft's Avatar
 
Join Date: Oct 2002
Location: Nashville, TN
Posts: 446
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
Liked: 10
I'm rusty on my EventGhost setup, but I'm pretty sure you can set up a trigger for when an application starts. If you can get the Logger running in EventGhost (the thing that logs everything happening on the system) look for an event called "Task.NewWindow.Control" or "Task.NewWindow.Control.Cmd". That's the event of your batch file starting up and you can run your script every time it sees that happen.
leewcraft is offline  
post #20 of 22 Old 04-12-2012, 02:17 AM - Thread Starter
AVS Special Member
 
Murilo's Avatar
 
Join Date: Nov 2003
Posts: 4,679
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 7 Post(s)
Liked: 12
I apologize for this again, the file is actually set up as an exe file, i was doing this from memory. I am back home now for awhile so no more mistakes.

Dont know if that makes a difference. So one last time i basically want event ghost to monitor or notice when the control.exe file is executed and then activate the input switch. So i dont need eventghost to trigger the control.exe file, just notice when its running to trigger the the input switch script created above.

When i run the .exe file a command window pops up. Event ghost logger seems to come up with 3 entries, and im really unsure how to add it, so that event ghost monitors when its running. I just dragged and dropped them but it does not seem to be working.

The log shows

"Task.NewWindow.Control"
"Task.Created.Control"
"Task.Activated.Control"

Either way im still not sure what to do with these and how to make event ghost monitor them. Im just curious how to link them to the input switch now? And here is my sad looking configuration below. I dont even know if eventghost is working, or watching or monitoring if the command program is running in eventghost?

I tried executing the command program manually by double clicking but there is no input switch on my receiver. And as mentioned above the input switch which is the python script does work, if i click and execute it manually in event ghost it does change the input on my receiver.

So I dont know if i have start event ghost monitoring, or if im missing something?

Any help would be greatly appreciated, i have found next to nothing in the way of support documentation on this program, i have no where to ask for help. Below is a picture of my poor looking configuration tree, which i have no real idea what to do with it.
LL
Murilo is offline  
post #21 of 22 Old 04-12-2012, 08:13 AM
Member
 
glorpsd's Avatar
 
Join Date: Apr 2009
Posts: 100
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
Liked: 14
Quote:
Originally Posted by Murilo View Post

"Task.NewWindow.Control"
"Task.Created.Control"
"Task.Activated.Control"


I think there are probably easier ways to do this that do not rely on EventGhost at all. You really should look upstream to what actually triggers the exe (or bat, sorry, I'm still unclear what you're describing) and then find a way to insert a new step in that process. I'd bet it's possible and a far better and more reliable approach, but I'll just go ahead and answer the EventGhost part.

You need to add a plug-in to your configuration. EG isn't tied in to all Windows events for external Windows proceses yet. You need to add the "Process Watcher" plug-in to get those. Choose "Add Plugin" then find that one from the installed plugins (Other->Process Wtacher) and add it to the Autostart section. Now you'll see the windows event stream appear in the EG status window when you start/start apps.

You'll need to start your program (and probably some others too) and see what gets generated as events for it. With luck something unique that signals that your app is started will show up. Watch the status window as you open & close programs to learn how these work. It will be named something like the 3 you listed above but probably start with Process.Created.[something] instead. The problem here is that *if* the exe is really running in an MS-DOS command window you may only see the command window process instead and *that* won't necessarily be a unique event. That's why I suspect you'd be better off solving this from another angle, but I didn't test running a proces from an MS-DOS command myself to see what EG also sees so you'll have to test it and figure out how that works. If you can find one (and with luck, unique) event, you'll then set up an EG macro that triggers only on that event. A macro "triggers" when any of the events inside it are "observed" to occur and it performs all the actions that are inside the scope of that macro and below that trigger event.

So first, create a new folder at the top of the tree and name it "Global Actions". Make sure it's enabled. Now add a new macro in the "GA" folder just created and give it a useful name and make sure it's enabled. Next add the unqiue event that you found when your app starts. You can drag the event from EG's explorer status pane onto (or just below) your macro or just add a new event to the macro and type the full name of the event exactly as it appeared in the status window. Finally add a EG->Python Script action to that same macro below the newly added event and paste in the python script code I gave you before to handle the HTTP communications that you need to switch inputs on the avr.

It should look kind of like this:
Code:
Tree
  |
  +Autostart
     |
     +Plugin: Process Watcher
  |
  +[folder]Global Actions
      |
      +[macro]Your Macro
         |
         +[event]Process.Created.YourApp
         +[action]Python Script
      |
      +Next Macro (not used
Please note that this is *conceptual*. Those aren't going to be the actual names. You need to figure them out and I can't do it from the info I have.

The new macro you add should have "global" scope (i.e., one that will run at all times since EG allows you to also activate and deactivate macros or groups of macros depending on conditions). Since you don't need EG for anything else at this point you can just have the one macro and nothing else in your configuration. That would be "global" as long as the Global Actions folder is always enabled and you don't set up anything to disable it from other events. Now whenever EG "sees" that event occur it will trigger all the Actions in the macro it's assigned to which in this case will be to run the one script which is below it in the macro and which sends the URL. Of course EG always has to be running on your system for any of that to work.

The standard EG install comes with a bunch of example xml files that you can load and learn from. You should take a look at how they set up some of the basics to get an idea how the app works. All of those examples will be far more than what you need here but the structures can be helpful to learn how to set it up to perform functions.
glorpsd is online now  
post #22 of 22 Old 04-12-2012, 07:17 PM - Thread Starter
AVS Special Member
 
Murilo's Avatar
 
Join Date: Nov 2003
Posts: 4,679
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 7 Post(s)
Liked: 12
Thanks for your help. Im going to read and experiment and follow your guidelines. At least i have some idea and direction now! I was looking at this program blind.

The only reason im going the monitoring route with eventghost, is because i would like the input to switch back, when the control.exe process is not running or terminated.
Murilo is offline  
Reply Home Theater Computers

User Tag List

Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page


Forum Jump: 

Posting Rules  
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off