Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: Call WSH script from web page Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
MartynD
Newbie
Newbie
Avatar

Joined: December 14 2004
Location: United Kingdom
Online Status: Offline
Posts: 13
Posted: December 27 2004 at 04:13 | IP Logged Quote MartynD

Am currently evaluating PH,(many thanks for a great piece of software,) with a view to using it as the engine in an HTPC/home automation project. Was hoping to use a web browser to control all functionality and therefore my eval time has been spent trying to call macros, functions, and send keystrokes and iR commands directly from a web page.

Have spent many (enjoyable) hours browsing the forums and helps files and, so far have nearly all the functionalitity I require.

Can call macros, send iR commands and send keystrokes, (for controlling media portal, http://mediaportal.sourceforge.net, worth a look,) but, would like to call WSH scripts from an HTML page.

Below is the HTML code I have been using to test functionality.

=====================================================
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Test Page</title>

<script language="JavaScript">
//Sendkeys
function f_sk(skeys)
{ document.execsendkeys.sendkeys.value = "ph_rtne(ph_sendkeys('" + skeys + "'))"; document.execsendkeys.submit(); }

//Run a macro
function macro(id)
{ document.execsendkeys.sendkeys.value = "ph_rtne(ph_macro('" + id.toUpperCase() + "'))"; document.execsendkeys.submit(); }

//Send iR remote commands
function f_cc(atype,aid,aparm1,aparm2)
{
document.ccform.type.value = atype;
document.ccform.btnid.value = aid;
document.ccform.parm1.value = aparm1;
document.ccform.parm2.value = aparm2;
document.ccform.submit();
}
</script>
</head>

<form method="post" action="/ph-cgi/ccbutton" name="ccform" target="blankframe">
<input type="hidden" name="type" value="">
<input type="hidden" name="btnid" value="">
<input type="hidden" name="parm1" value="">
<input type="hidden" name="parm2" value="">
<input type="hidden" name="nexturl" value="">
</form>

<form method="post" action="/ph-cgi/execsendkeys" name="execsendkeys" target="blankframe">
<input type="hidden" name="sendkeys">
</form>

<input onclick="f_sk('{downarrow}');" type="button" value="Cursor Down">
<input onclick="macro('UK GOLD');" type="button" value="UK Gold">
<input onclick="f_cc(1,'SKY DIGITAL',15,0);" type="button" value="Favourites">
<input onclick="f_sk('ph_runscript_0("testscript.vbs","vbscript",1,0,"test")');" type="button" value="Call Test Function">

</body>
</html>
=====================================================
As you can see I have buttons for testing but the one I'm having real problems with is the 'Call Test Function' button.

Have tested the script, (a simple 'Hello World' affair,) from within PH successfuly. Can call it from the web page by calling a macro that calls the code, and will continue to do so if it's the only option remaining but would prefer to call it directly from code on the web page. (Have also tried fully pathing the vbs script name)

Many thanks.
Back to Top View MartynD's Profile Search for other posts by MartynD
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: December 27 2004 at 18:02 | IP Logged Quote TonyNo

Are you saying that the code above does not work? If so, I would guess that your problem would be with the quotes used in you onclick statement. I'm no quote master, but, it has burned me before. Try this...

<input onclick="f_sk('ph_runscript_0(\'testscript.vbs\',\'vbscript\',1,0,\'test\')');" type="button" value="Call Test Function">

Tony
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
MartynD
Newbie
Newbie
Avatar

Joined: December 14 2004
Location: United Kingdom
Online Status: Offline
Posts: 13
Posted: December 28 2004 at 02:26 | IP Logged Quote MartynD

Tony

Many thanks for taking a look. Aplogies about not being more specific than 'having a problem with'.

When I run the page above it loads into M$IE v6 with no errors, and the 'Call Test Function' button does nothing but no errors are reported either.

Have taken your advice and replaced the " with ' but then IE reports an error when the page is loaded. (Error in the form of ! in yellow triangle at left end of status bar.) It's complaining about 'unterminated string constant' but the line/col reference is at the ' before ph_runscript.

I think I've tried most combinations of ' and ". Have tried ph.runscript & ph_runscript.

Will keep trying.

Seasons greetings

Martyn
Back to Top View MartynD's Profile Search for other posts by MartynD
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: December 28 2004 at 18:21 | IP Logged Quote dhoward

Martyn,

Glad to hear you're enjoying PowerHome. Checked out your HTML code and duplicated what you are attempting and found a couple of problems. As Tony stated, the single quotes, double quotes, and embedding them within one another will get you. The proper escaping for the line would be:

<input onclick="f_sk('ph_runscript_0(~~\'testscript.vbs~~\',~~\'vbscript~~\',1,0,~~\'test~~\')');" type="button" value="Call Test Function">

However, this still wont produce the desired result. Within your HTML page, the javascript function f_sk is calling the ph_sendkeys function. When this is properly escaped as in the above line, you will send the ph_runscript function as a "string" to the ph_sendkeys function resulting in keystrokes being produced rather than the function being evaluated.

The ph-cgi function that would be best suited would be the evalformula function. Below, is your HTML page reworked so that the ph_runscript function is called using this method.

**********************************************j
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Test Page</title>

<script language="JavaScript">
//Sendkeys
function f_sk(skeys)
{ document.execsendkeys.sendkeys.value = "ph_rtne(ph_sendkeys('" + skeys + "'))"; document.execsendkeys.submit(); }


//Evaluate a formula
function f_formula(formula)
{ document.evalformula.formula.value = formula; document.evalformula.submit(); }

//Run a macro
function macro(id)
{ document.execsendkeys.sendkeys.value = "ph_rtne(ph_macro('" + id.toUpperCase() + "'))"; document.execsendkeys.submit(); }

//Send iR remote commands
function f_cc(atype,aid,aparm1,aparm2)
{
document.ccform.type.value = atype;
document.ccform.btnid.value = aid;
document.ccform.parm1.value = aparm1;
document.ccform.parm2.value = aparm2;
document.ccform.submit();
}
</script>
</head>

<form method="post" action="/ph-cgi/ccbutton" name="ccform" target="blankframe">
<input type="hidden" name="type" value="">
<input type="hidden" name="btnid" value="">
<input type="hidden" name="parm1" value="">
<input type="hidden" name="parm2" value="">
<input type="hidden" name="nexturl" value="">
</form>

<form method="post" action="/ph-cgi/execsendkeys" name="execsendkeys" target="blankframe">
<input type="hidden" name="sendkeys">
</form>

<form method="post" action="/ph-cgi/evalformula" name="evalformula" target="blankframe">
<input type="hidden" name="formula">
</form>

<input onclick="f_sk('{downarrow}');" type="button" value="Cursor Down">
<input onclick="macro('UK GOLD');" type="button" value="UK Gold">
<input onclick="f_cc(1,'SKY DIGITAL',15,0);" type="button" value="Favourites">
<input onclick="f_formula('ph_runscript_0(\'testscript.vbs\',\'vbscript\',1,0,\'test\')');" type="button" value="Call Test Function">

</body>
</html>
*************************************************

You would probably want to update the other buttons as well. The execsendkeys function is a holdover from earlier days before the existence of the evalformula function and is pretty much outdated. Since the evalformula function can execute any formula, you can send keystrokes, launch macros, or play IR all from the one function. Below would be an example reworked to use this single function:

**********************************************

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Test Page</title>

<script language="JavaScript">
//Evaluate a formula
function f_formula(formula)
{ document.evalformula.formula.value = formula; document.evalformula.submit(); }
</script>
</head>

<form method="post" action="/ph-cgi/evalformula" name="evalformula" target="blankframe">
<input type="hidden" name="formula">
</form>

<input onclick="f_formula('ph_sendkeys(\'{downarrow}\')');" type="button" value="Cursor Down">
<input onclick="f_formula('ph_macro(\'UK GOLD\')');" type="button" value="UK Gold">
<input onclick="f_formula('ph_ir(\'SKY DIGITAL\',15)');" type="button" value="Favourites">
<input onclick="f_formula('ph_runscript_0(\'testscript.vbs\',\'vbscript\',1,0,\'test\')');" type="button" value="Call Test Function">

</body>
</html>

*********************************************

Hope you had a great holiday and let me know if you have any other questions.

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
MartynD
Newbie
Newbie
Avatar

Joined: December 14 2004
Location: United Kingdom
Online Status: Offline
Posts: 13
Posted: December 29 2004 at 01:58 | IP Logged Quote MartynD

Dave

Wow! That pretty much covers any function I'll ever need to call from PH.

Many thanks for the examples. Everything explained very clearly.

Thank you

Martyn
Back to Top View MartynD's Profile Search for other posts by MartynD
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum