Please login or register.

Login with username, password and session length

Author Topic: Can SmartMacro trigger a vbscript?  (Read 9792 times)

jrwhit

  • Full Member
  • ***
  • Helpful Post Rating: 2
  • Posts: 39
Can SmartMacro trigger a vbscript?
« on: August 07, 2009, 04:31:25 AM »

I am trying to get AHP to trigger a vbscript. I open Macro Designer - Execute Windows Program and point it to my .vbs file.
When I right-click on the new macro created and click trigger macro I get what sounds like a Windows error ding and nothing else happens.
The vbs file in question actually goes out to the web, grabs the current temp in my town and then uses text to speech to announce it to me.
Works great when I double click from desktop. My plan is to then call it from BVC but AHP will have to play a part, I think. Anyone have any success with this?
Logged

ITguy

  • Sr. Member
  • ****
  • Helpful Post Rating: 8
  • Posts: 105
Re: Can SmartMacro trigger a vbscript?
« Reply #1 on: August 07, 2009, 10:05:03 AM »

I've found AHP to be a little "picky" about what works and what doesn't.  You might try putting the vbs call inside a simple .bat file.  Something like:

@ECHO OFF
cscript "GetTemp.vbs"

Be sure to use the "browse" button when creating the macro so that AHP will pick up the correct path!

I'm not a Visual Basic expert by any means, but the .bat has worked for me in other situations where a direct call wouldn't work.  If that doesn't do the trick, you can try AutoHotKey, which lets you take a .bat file and turn it into a .exe.

ITguy

Logged

HA Dave

  • Hero Member
  • *****
  • Helpful Post Rating: 175
  • Posts: 7127
Re: Can SmartMacro trigger a vbscript?
« Reply #2 on: August 07, 2009, 10:06:00 AM »

........... actually goes out to the web, grabs the current temp in my town and then uses text to speech to announce it to me.
Works great when I double click from desktop. My plan is to then call it from BVC but AHP will have to play a part, I think. Anyone have any success with this?

I have been using weatheraloud with my BVC setup for more than a couple years now.

The weatheraloud program is a little $20 program... and one of a few "aloud" products. It isn't overly user friendly to be honest... but once you get the setting correct its pretty simple. Weatheraloud reads the RRS feed from the weather underground site and stores [saves] the file as a wav file. I have it set to retrieve weather info and save the file right in the BVC audio file every 30 minutes. Everytime it retrieves a new file it writes-over or replaces the previous file.

Knightrider wrote a setup directions for WeatherAloud at Bill's forum here: http://wgjohns.com/forums/index.php?topic=29.msg118#msg118

Then when I ask BVC for the weather.... it merely plays the weather audio file. No AHP involved. This can be seen in this YouTube Video.
« Last Edit: August 07, 2009, 10:33:39 AM by Dave_x10_L »
Logged
Home Automation is an always changing technology

jrwhit

  • Full Member
  • ***
  • Helpful Post Rating: 2
  • Posts: 39
Re: Can SmartMacro trigger a vbscript?
« Reply #3 on: August 07, 2009, 02:53:20 PM »

Thanks for your responses. ITGUY, your batch file made it work  -  albeit sporadically. Might have to use the Autohotkey to exe option to make it foolproof.
Dave, I have tried WeatherAloud. It worked OK but I was just trying to cut out a little overhead. One program calling another program to call yet a third seems like overkill.
I'll just keep massaging it until I get it to work as expected.
Logged

ITguy

  • Sr. Member
  • ****
  • Helpful Post Rating: 8
  • Posts: 105
Re: Can SmartMacro trigger a vbscript?
« Reply #4 on: August 07, 2009, 03:11:08 PM »

Glad that helped.  When you find a really solid solution, please be sure to post the answer!

ITguy
Logged

systemdm

  • Sr. Member
  • ****
  • Helpful Post Rating: 17
  • Posts: 76
Re: Can SmartMacro trigger a vbscript?
« Reply #5 on: August 07, 2009, 04:02:46 PM »

jrwhit, would you post your vbscript?   I'm trying to learn vb and it would be nice to see some scripts I could actually use.
Thanks...DR
Logged

jrwhit

  • Full Member
  • ***
  • Helpful Post Rating: 2
  • Posts: 39
Re: Can SmartMacro trigger a vbscript?
« Reply #6 on: August 08, 2009, 01:34:21 AM »

Sure, systemdm,  I'll post it.
In order to use this program you will have to go to www.webscrape.com and download a small program called Pagescrape. That is what connects to the web page with the current temp. It is a screen scraping program that allows the use of regular expressions to retrieve only the data that you want to collect. It has several examples on this page of pscrape command lines that you can use. Unfortunately, several of the web pages have changed, so pscrape errors out on several of the examples. I have a long way to go to master regular expressions but this one works for my town.
Hpe you can get some good out of it.

'Program to connect to weather web page, retrieve current temp, write it to a temp file
'then send output to Windows text-to-speech engine to read it back to you and then delete temp file.

Option Explicit

Const SVSFlagsAsync = 1
const SVSFPurgeBeforeSpeak = 2

Dim Speech
Dim FSO
Dim shell
Dim filename
Dim run
Dim sText


CreateObjects
Announce_temp
DestroyObjects
Quit


Sub Announce_temp()
       
   ' Create the objects we need
   Set shell = CreateObject("WScript.Shell")
   Set fso = CreateObject("Scripting.FileSystemObject")

   ' Generate Temp Filename which PageScrape will output to
   fileName = fso.GetTempName
   ' Build command, in a VBS string literal, " must be escaped as ""
   ' The -o option tells PageScrape to write the matched text to a file
   run = "pscrape -u""http://www.city-data.com/forecast/w-Knoxville-Iowa.html"" -e""Temperature:(<.*>)*[^<]*(\d+)\D"" -b2 -f""Current Temperature in Knoxville is \$2 degrees"" -o""" & fileName & """"

   ' Run PageScrape synchronously in a hidden window
   ' The 0 specifies that the Window should be hidden
   ' The 1 specifies that we should wait for the command to complete
   ' before continuing
   shell.Run run, 0, 1

   ' Open the Temp File and read its contents
   stext = fso.OpenTextFile(fileName, 1).ReadAll

   ' Delete the Temp file
   fso.DeleteFile filename
   SpeakText sText
End Sub

Sub SpeakText(sText)
        On Error Resume Next
        Speech.Speak sText, SVSFlagsAsync + SVSFPurgeBeforeSpeak
        Do
               Sleep 100
        Loop Until Speech.WaitUntilDone(10)
End Sub

Sub StopSpeaking()
        On Error Resume Next
        Speech.Speak vbNullString, SVSFPurgeBeforeSpeak
        Set Speech = Nothing
End Sub

Sub CreateObjects
        Set Speech = CreateObject("SAPI.SpVoice")
        Set FSO = CreateObject("Scripting.FileSystemObject")
End Sub

Sub DestroyObjects
        Set Speech = Nothing
        Set FSO = Nothing
End Sub

Sub Sleep(nTimeout)
        WScript.Sleep nTimeout
End Sub

Sub Quit
        WScript.Quit
End Sub
Logged

systemdm

  • Sr. Member
  • ****
  • Helpful Post Rating: 17
  • Posts: 76
Re: Can SmartMacro trigger a vbscript?
« Reply #7 on: August 09, 2009, 12:16:57 AM »

Thanks jrwhit....$ helpful
Logged
 

X10.com | About X10 | X10 Security Systems | Cameras| Package Deals
© Copyright 2014-2016 X10.com All rights reserved.