Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Start VB-script with parameter


  • Please log in to reply
25 replies to this topic
m1m3r
  • Members
  • 29 posts
  • Last active: Mar 08 2012 08:59 PM
  • Joined: 29 Apr 2006
I have a VB-script that triggers the computers speech synthesis and speaks whatever I pass to the script. Now I want to use this from an AHK script but I can't get it to work and I don't know why...

This
Run, C:\Scripts\speak.vbs, %Name%
(the variable %Name% is not empty and works fine with other commands) gives me

---------------------------
Windows Script Host
---------------------------
Script:	C:\Scripts\speak.vbs
Line:	4
Char:	1
Error:	Subscript out of range
Code:	800A0009
Source: 	Microsoft VBScript runtime error
but writing

c:\scripts\speak.vbs testing
in a dos prompt works just fine - the word "testing" is spoken.

What am I missing...?

n-l-i-d
  • Guests
  • Last active:
  • Joined: --
You don't need VBS for that...

TTS() Text To Speech using COM

:wink:

m1m3r
  • Members
  • 29 posts
  • Last active: Mar 08 2012 08:59 PM
  • Joined: 29 Apr 2006
I know there are some AHK scripts for TTS but this VB script is already used by other applications and it would be very nice to use it with AHK as well.

Jon
  • Members
  • 349 posts
  • Last active: Aug 30 2011 08:35 PM
  • Joined: 28 Apr 2004
run cscript.exe "%a_workingdir%\test.vbs"

or

run cmd /c cscript.exe "%a_workingdir%\test.vbs"

The only problem is that the command prompt window shows. You might be able to use use CMDret to avoid that-

CMDret - AHK functions

Supercalifragilistic
  • Guests
  • Last active:
  • Joined: --
The basic scripts should be :
the AHK one :
VBSScript := "D:\LineCol.vbs"
Line := 10
Row := 24
RunWait, cscript.exe //nologo "%VBSScript%" "%Line%" "%Row%",,Hide
Use RunWait to ... wait for the VBS script to finish to be executed, else use Run.
the Hide parameter ... hide the command prompt window.
The VBS one (LineCol.vbs):
If WScript.Arguments.Count <> 2 Then
	msgbox "Not OK"
Else
	Line = WScript.Arguments.Item(0)
	Row = WScript.Arguments.Item(1)m(2)
End If

msgbox "Param from command line : " & Line & "," & Row
Thats OK if you don't need to retreive results.
If you need to get back results, you can use CMDret or pass back the result with the clipboard. For that I use the COM DLL of AutoIt, AutoItX.

m1m3r
  • Members
  • 29 posts
  • Last active: Mar 08 2012 08:59 PM
  • Joined: 29 Apr 2006
Thanks guys,

Run, c:\windows\system32\cscript.exe c:\scripts\speak.vbs "%Name%",, hide
did the trick.

Supercalifragilistic
  • Guests
  • Last active:
  • Joined: --
just a few comments :
1) It works too without the need to specify the path of cscript.exe
2) I use the notation "%Name%" for the parameters to be able to send parameters with space in them. If you are shure that there isn't any space character in your parameters, ou can use the notation Name instead (without "% and %"...

m1m3r
  • Members
  • 29 posts
  • Last active: Mar 08 2012 08:59 PM
  • Joined: 29 Apr 2006

just a few comments :
1) It works too without the need to specify the path of cscript.exe
2) I use the notation "%Name%" for the parameters to be able to send parameters with space in them. If you are shure that there isn't any space character in your parameters, ou can use the notation Name instead (without "% and %"...

1. It does.
2. There are spaces in %Name%, therefore I use quotation marks.

A follow-up question; is there anyway to trigger an environment variable containing the path to a VB-script? If I run
%tts% "this is a test"
from a dos prompt, the words are spoken. How to run it from an AHK script?

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
remove #NoEnv from the top of the script, or you can use EnvGet to get where tts is.

m1m3r
  • Members
  • 29 posts
  • Last active: Mar 08 2012 08:59 PM
  • Joined: 29 Apr 2006
I don't have #NoEnv and I still haven't found a way to trigger %tts% from AHK.

Supercalifragilistic
  • Guests
  • Last active:
  • Joined: --

A follow-up question; is there anyway to trigger an environment variable containing the path to a VB-script? If I run

%tts% "this is a test"
from a dos prompt, the words are spoken. How to run it from an AHK script?

I don't understand well what you want. May be it's because I'm not native language english... Please show the full command you enter under dos prompt.
If the question is how to transfert the content of an environnement variable to a vbscript, the answer is : like the others params.
For instance :
VBSScript := "D:\An example.vbs"
RunWait, cscript.exe //nologo "%VBSScript%" "%A_WinDir%",,Hide
May be I didn't understood your request.

If you want to make the PC speak, try this : AHK script :
VBSScript := "D:\Speak to me.vbs"
TextToSpeak := "Hello you"
RunWait, cscript.exe //nologo "%VBSScript%" "%TextToSpeak%",,Hide
VBScript :
Dim say

If WScript.Arguments.Count <> 1 Then
   msgbox "Not OK"
Else
   TextToSpeach = WScript.Arguments.Item(0)
   Set say = CreateObject("SAPI.SpVoice")
   say.speak TextToSpeach
End If

** Not tested ** (As I didn't install text-to-speach on py PC) ... but should work...

Tell me if it's what you whant and if it is OK...

m1m3r
  • Members
  • 29 posts
  • Last active: Mar 08 2012 08:59 PM
  • Joined: 29 Apr 2006
English isn't my native language either... 8)

First, I have this in Windows XP;

<!-- m -->http://img338.images...e=image1rv4.jpg<!-- m -->

Now, if I enter this;

<!-- m -->http://img338.images...e=image2ha4.jpg<!-- m -->

the computer's speech synthesis says "this is a test".

Supercalifragilistic
  • Guests
  • Last active:
  • Joined: --
I must say I didn't knew the first dialog box you shown, "Edit system variable"
I tried :
EnvGet, OutputVar, tts
msgbox %OutputVar%
to see if there is an environement variable called tts, it isn't the case.
I seen the (affected ?) value of this variable is the path and the name of your vbs file.
Of course in Windows, if you double click a vbs file, it is executed.
I think that is what is done by :
%tts% "this is a test"
So what you done via the Run dialog box is the same as to execute your script (c:\scripts\speak.vbs) with "this is a test" as parameter.
%tts% "this is a test"
is the same as to write in the Window's Run dialog
c:\scripts\speak.vbs "this is a test"
(It should be usefull to see the content of the VBS script itself...)
But in AHK (as far as I know),
c:\scripts\speak.vbs "this is a test"
can't work. You must specify the program used to run the vbs file. So to run your script you should write something like that :
VBSScript := "c:\scripts\speak.vbs"
TextToSpeak := "this is a test"
RunWait, cscript.exe //nologo "%VBSScript%" %TextToSpeak%",,Hide


Supercalifragilistic
  • Guests
  • Last active:
  • Joined: --
Hope it helps. I go to sleep. Bye. :D :D :D

Supercalifragilistic
  • Guests
  • Last active:
  • Joined: --
I forgot a "
RunWait, cscript.exe //nologo "%VBSScript%" "%TextToSpeak%",,Hide