passing arguments to MacScript

M

mansky99

Hi,
I have a Perl script that I want to call from VB via the MacScript
function via Applescript. The Perl script takes an argument and I am having
trouble getting MacScript to handle the passed argument.

Here's the snippet of VB code:

.... in-line Applescript here
Etime = MacScript(ASArg)
Debug.Print Str(Etime)

'Call Perl script, via Applescript to convert Etime to HH:MM:SS format
ASArg2 = "set Etime2 to do shell script
""/Users/ed/Codes/DBscripts/ConvertTime.pl -t """ + Str(Etime)
Debug.Print ASArg2
Debug.Print Etime2
Etime2 = MacScript(Str(ASArg2))

Here's the debug output:

190
set Etime2 to do shell script "/Users/ed/Codes/DBscripts/ConvertTime.pl -t "
190

The argument I want to pass (Etime) is the returned value from a previous
Applescript call via MacScript.

If I declare ASArg2 to be a String, I get a Run-time error #5. If I declare
ASArg2 as a Variant and wrap ASArg2 inside a Str function inside the second
call to MacScript, I get a run-time error #13.

The problem seems to me to get the last literal quote to enclose the passed
argument.

So the question is, how, in VB, do I embed a variable inside a literal
string and thereby pass an argument thru MacScript, to the target script?

Any ideas are greatly appreciated!

Ed
 
J

JE McGimpsey

mansky99 said:
So the question is, how, in VB, do I embed a variable inside a literal
string and thereby pass an argument thru MacScript, to the target script?

How about

ASArg2 = "set Etime2 to do shell script
""/Users/ed/Codes/DBscripts/ConvertTime.pl -t " & Str(Etime) & """"

(or

ASArg2 = "set Etime2 to do shell script " & _
"""/Users/ed/Codes/DBscripts/ConvertTime.pl -t " & _
Str(Etime) & """"

But I'm a bit confused - you have your

Debug.Print Etime2

line before you assign the result of the MacScript (which has its own
applescript Etime2 variable) to the VBA variable Etime2. That should
always print #NOTHING# or a null string, depending on whether/how you
declared Etime2.

I'm also a little confused as to why you'd use MacScript/Perl to convert
the time to a string, rather than VBA, which will be far faster
(MacScript has a *lot* of overhead).

For instance, if Etime is the number of seconds since midnight:

Dim Etime2 As String
Etime2 = Format(TimeSerial(0, 0, Etime), "hh:mm:ss")
 
M

mansky99

Moving the literal quote to the end did the trick! It works! Terrific!

The statement Debug.Print Etime2 is an error from my cut-and-paste efforts
to make the original post. Sorry, just ignore that statement, it's not in the
original VB code.

The reason I go and call the Perl script. is that the original variable
(Etime) is the elapsed time in seconds of the currently playing track in
iTunes (a voice memo that is being transcribed in Word). I want the elapsed
time to be inserted into Word using the format HH:MM:SS and it's easier to
re-format the time in Perl than in Applescript. I tried the TimeValue
function in VB, but couldn't get it to work on the Mac.

Thanks again!


Ed
 
J

JE McGimpsey

mansky99 said:
The reason I go and call the Perl script. is that the original variable
(Etime) is the elapsed time in seconds of the currently playing track in
iTunes (a voice memo that is being transcribed in Word). I want the elapsed
time to be inserted into Word using the format HH:MM:SS and it's easier to
re-format the time in Perl than in Applescript. I tried the TimeValue
function in VB, but couldn't get it to work on the Mac.

Using TimeSerial as I suggested should be far and away more efficient
than running it through MacScript.

TimeValue shouldn't work at all - the argument for TimeValue is a string
that represents a formatted time.
 
M

mansky99

Yes, indeed. I just tried Format with TimeSerial and it also works just fine.
I wanted to test passing an argument thru MacScript and Applescript to Perl
to see if I could execute a Perl script from VB and get results back. I can
indeed. Will go with the TimeSerial function, but good to know how to call
Perl from VB. :)

Thanks again!

Ed
 
J

JE McGimpsey

mansky99 said:
Will go with the TimeSerial function, but good to know how to call
Perl from VB.

There are certainly situations for which Perl would be a better choice.
Right tool for the right job, and all that...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top