Page 1 of 1

'do' Command

Posted: Wed Dec 02, 2009 1:32 am
by Kevin
1. How do you detect of the transcript executed by the do command was successful?
2. How do you get the result of the do command?'

Re: 'do' Command

Posted: Wed Dec 02, 2009 10:38 am
by SparkOut
Hi Kevin,
I can't give you any ideas about Apple Script, but for VBScript you would write your routine so that any errors are noted in the results returned. By setting a variable named "result" in the VBS routine, you can return that value to RunRev which receives it in the result.

So you would be able to do something like the following (which is an example of calling a vbscript routing to create a shortcut icon - something which was asked in this post http://forums.runrev.com/phpBB2/viewtop ... 192#p19192 - although a simpler way to do this natively in revTalk was also pointed out)

Code: Select all

On Error Resume Next
result = "OK"
Set oWS = CreateObject("WScript.Shell")
If Err <> 0 then
  result = "Error creating shell"
End If

'proceed if there was not an error
If result = "OK" then
  sLinkFile = "<path for the destination of the shortcut>.lnk"
  Set oLink = oWS.CreateShortcut(sLinkFile)
  If Err <> 0 then
    result = "Error creating shortcut link file"
  End If
End If

'proceed if everything is still ok
If result = "OK" then
  oLink.TargetPath = "<path to your application>.exe"
  oLink.Description = "<uh... a description>"
  oLink.IconLocation = "<path to your icon file, which naturally will be the same as your application that has the embedded icon>.exe,0"
  'the trailing 0 is the index number of the icon to use inside the icon file. I confess I 
  'don't know what the difference is when there's only one icon for your application.
  'I have used index 0 or 1 interchangeably, while my applications contain 16 versions
  'of the same icon at different sizes and bit depths. Windows seems to display the right
  'resolution version of it whatever. At least for me, in my present experience.
  oLink.WindowStyle = 1
  oLink.Save

  If Err <> 0 then
    result = "Error creating shortcut icon"
  End If
End If
Set oWS = nothing
So when you do the vbscript, the result (retuned to RunRev) will contain "OK" unless it has been overwritten by a failure or error message which you can parse and handle appropriately.

HTH
SparkOut

Re: 'do' Command

Posted: Wed Dec 02, 2009 4:00 pm
by Kevin
Actually, I am only using Transcript with the "do" command not any native scripting language.

Re: 'do' Command

Posted: Thu Dec 03, 2009 7:00 am
by Janschenkel
The content of the 'do' command is executed within the context of your running handler. In other words, if your script looks like:

Code: Select all

on mouseUp
  do "get the system date"
  answer it
end mouseUp
clicking the button will display the date. That's because the get command puts the result of the expression into the local it variable.

Expanding on that script example, let's confirm you can call any function or command in the message path:

Code: Select all

on mouseUp
  do "get MyFunction()"
  answer it
  do "MyCommand 2"
  answer the result
end mouseUp
function MyFunction
  return "This is the return value from MyFunction"
end MyFunction
command MyCommand pTimes
  beep pTimes
  return "This is the return value from MyCommand"
end MyCommand
so indeed it is as if you magically inserted a piece of code at runtime.

And that brings us to error handling. If there is an syntax error in your do statement, an exception will be thrown and your script will come to a halt. And if your statement has no syntax errors, you're still dependent on what it does and how that handles its errors. See also this blog post Error Handling in revTalk for the mixed approach that is error handling inside revTalk.

HTH,

Jan Schenkel.