AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Start VB-script with parameter
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
m1m3r



Joined: 29 Apr 2006
Posts: 27
Location: Sweden

PostPosted: Sat Jun 16, 2007 2:27 pm    Post subject: Start VB-script with parameter Reply with quote

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
Code:
Run, C:\Scripts\speak.vbs, %Name%

(the variable %Name% is not empty and works fine with other commands) gives me

Code:
---------------------------
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

Code:
c:\scripts\speak.vbs testing

in a dos prompt works just fine - the word "testing" is spoken.

What am I missing...?
Back to top
View user's profile Send private message
n-l-i-d
Guest





PostPosted: Sat Jun 16, 2007 2:56 pm    Post subject: Reply with quote

You don't need VBS for that...

TTS() Text To Speech using COM

Wink
Back to top
m1m3r



Joined: 29 Apr 2006
Posts: 27
Location: Sweden

PostPosted: Sat Jun 16, 2007 3:05 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Jon



Joined: 28 Apr 2004
Posts: 373

PostPosted: Sat Jun 16, 2007 7:22 pm    Post subject: Reply with quote

Code:
run cscript.exe "%a_workingdir%\test.vbs"


or

Code:
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
Back to top
View user's profile Send private message Send e-mail
Supercalifragilistic
Guest





PostPosted: Sat Jun 16, 2007 8:05 pm    Post subject: Reply with quote

The basic scripts should be :
the AHK one :
Code:
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):
Code:
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.
Back to top
m1m3r



Joined: 29 Apr 2006
Posts: 27
Location: Sweden

PostPosted: Sun Jun 17, 2007 9:44 am    Post subject: Reply with quote

Thanks guys,

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

did the trick.
Back to top
View user's profile Send private message
Supercalifragilistic
Guest





PostPosted: Sun Jun 17, 2007 2:47 pm    Post subject: Reply with quote

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 %"...
Back to top
m1m3r



Joined: 29 Apr 2006
Posts: 27
Location: Sweden

PostPosted: Sun Jun 17, 2007 3:00 pm    Post subject: Reply with quote

Supercalifragilistic wrote:
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
Code:
%tts% "this is a test"

from a dos prompt, the words are spoken. How to run it from an AHK script?
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6772
Location: Pacific Northwest, US

PostPosted: Sun Jun 17, 2007 5:48 pm    Post subject: Reply with quote

remove #NoEnv from the top of the script, or you can use EnvGet to get where tts is.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
m1m3r



Joined: 29 Apr 2006
Posts: 27
Location: Sweden

PostPosted: Sun Jun 17, 2007 6:12 pm    Post subject: Reply with quote

I don't have #NoEnv and I still haven't found a way to trigger %tts% from AHK.
Back to top
View user's profile Send private message
Supercalifragilistic
Guest





PostPosted: Sun Jun 17, 2007 6:36 pm    Post subject: Reply with quote

m1m3r wrote:
A follow-up question; is there anyway to trigger an environment variable containing the path to a VB-script? If I run
Code:
%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 :
Code:
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 :
Code:
VBSScript := "D:\Speak to me.vbs"
TextToSpeak := "Hello you"
RunWait, cscript.exe //nologo "%VBSScript%" "%TextToSpeak%",,Hide

VBScript :
Code:
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...
Back to top
m1m3r



Joined: 29 Apr 2006
Posts: 27
Location: Sweden

PostPosted: Sun Jun 17, 2007 7:15 pm    Post subject: Reply with quote

English isn't my native language either... Cool

First, I have this in Windows XP;

http://img338.imageshack.us/my.php?image=image1rv4.jpg

Now, if I enter this;

http://img338.imageshack.us/my.php?image=image2ha4.jpg

the computer's speech synthesis says "this is a test".
Back to top
View user's profile Send private message
Supercalifragilistic
Guest





PostPosted: Sun Jun 17, 2007 10:08 pm    Post subject: Reply with quote

I must say I didn't knew the first dialog box you shown, "Edit system variable"
I tried :
Code:
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 :
Code:
%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.
Code:
%tts% "this is a test"
is the same as to write in the Window's Run dialog
Code:
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),
Code:
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 :
Code:
VBSScript := "c:\scripts\speak.vbs"
TextToSpeak := "this is a test"
RunWait, cscript.exe //nologo "%VBSScript%" %TextToSpeak%",,Hide
Back to top
Supercalifragilistic
Guest





PostPosted: Sun Jun 17, 2007 10:10 pm    Post subject: Reply with quote

Hope it helps. I go to sleep. Bye. Very Happy Very Happy Very Happy
Back to top
Supercalifragilistic
Guest





PostPosted: Sun Jun 17, 2007 10:13 pm    Post subject: Reply with quote

I forgot a "
Code:
RunWait, cscript.exe //nologo "%VBSScript%" "%TextToSpeak%",,Hide
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group