Author Topic: Trying to write pretty simple scripts is turning out to be very exasperating!!!  (Read 47646 times)

ajax

  • Junior Member
  • **
  • Posts: 25
    • View Profile
Still trying to do what provoked a previous post (http://forum.multicommander.com/forum/index.php/topic,2212.0.html) but am past the documentation stage.  The MultiScript debugger does some nice things but even using it success is quite illusive.  Here are some suggestions which I think would make the debugger much more useful.

  • Need to be able to copy text from the panel that displays values, that the variables get set to, which can then be pasted elsewhere.
  • Before executing one of the MC.xxx commands that command needs to be expanded (i.e., variable substitution completed) and then displayed prior to being executed.

Based on inspection of variable values my scripts work correctly but something bad is happening when MC.xxx commands are invoked.

A minor suggestion would be to add a horizontal scroll bar to the panel used for outputting debugger results.  Even on my wide screen display the values are often out of view.

ajax

  • Junior Member
  • **
  • Posts: 25
    • View Profile
Finally succeeded to get a simple script to work.  Never did figure out what was wrong with prior attempts but a bit of trial and error succeeded.  Now I'd like to figure out how to pass a parameter when invoking the script.  From documentation it looks like this means the script must be launched from the command line but there must be some not so obvious secret to making this work.

I chose the "Alias" button when using "Configuration>User Defined Commands" to create a multiscript.  There is an entry that shows up in the panel displayed when selecting "Configuration>Manage Aliases".  However, nothing seems to happen when the alias name is entered on the command line.

What do I need to do now?

AlanJB

  • VIP Member
  • *****
  • Posts: 436
  • VERY old Programmer
    • View Profile
Did you look here: http://multicommander.com/docs/aliases

to make sure your alias is correctly configured?

ajax

  • Junior Member
  • **
  • Posts: 25
    • View Profile
In my case the Alias Manager screen lists the name I assigned to the multiscript on the left and a value of @d037fc176448408cb5c744d5bc62ae33 on the right.  That value is what is displayed as the "Unique ID" in the upper right corner of the script editor for the script I want to invoke.

The script works fine in Multicript Debugger but it looks to me as if you cannot test the parameter passing in the debugger.  If that is possible I could use some help figuring out how to do that.  I'm not even able to invoke it without a parameter from the command line.

AlanJB

  • VIP Member
  • *****
  • Posts: 436
  • VERY old Programmer
    • View Profile
Could you post your MultiScript source here, please?

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4449
    • View Profile
    • Multi Commander
In my case the Alias Manager screen lists the name I assigned to the multiscript on the left and a value of @d037fc176448408cb5c744d5bc62ae33 on the right.  That value is what is displayed as the "Unique ID" in the upper right corner of the script editor for the script I want to invoke.

The script works fine in Multicript Debugger but it looks to me as if you cannot test the parameter passing in the debugger.  If that is possible I could use some help figuring out how to do that.  I'm not even able to invoke it without a parameter from the command line.

If you look at one of the example script that are there after install . "Google Search" there is an alias for this command to.. so when you type "g  <text>" in the command line field.. the script is run. and the script picks up the arguments sent to the script before sending everything to the browser.

If you show the code and descibe what you are trying to do. I think it would be easier to say what you should do


ajax

  • Junior Member
  • **
  • Posts: 25
    • View Profile
It looks like the problem invoking the multiscript using an alias was attributed to a coding error.  In that, the script probably did execute but when nothing appeared to happen this was not apparent.  However now that I can confirm that it is invoked I'm having trouble picking up the value entered for a parameter.

As requested the script follows:
Code: [Select]
@var $suffix = GetTagValue("${param:0}");
@var $message = "Request to Create a Hard Link (Alias)";
$message += "\nParam0=" + $suffix;
if(StrLen($suffix) <= 0)
{
$suffix = "L1";
}
else if (StrLen($suffix) > 5)
{
$suffix = "L9";
}
@var $filename = GetTagValue("${sourcefocusname}");
@var $linkname = StrSub($filename, 0, StrRFind($filename, "."));
@var $linkext = StrTrimLeft($filename, $linkname);
$linkname += "." + $suffix + $linkext;
@var $linkpath = GetTagValue("${targetpath}");
$message += "\nLinkPath=" + $linkpath;
$message += "\nLinkName=" + $linkname;
@var $tofile = GetTagValue("${sourcefocuspath}");
$message += "\nToFile=" + $tofile;
@var $result = MessageBox("Alias Make", $message, 1);
if($result == 1)
{
MC.Utils.CreateLink ASADMIN LNKTYPE=1 LNKTRG=${sourcefocuspath} LNKSRC=${targetpath}\{$linkname}
}
As you can see I'm assuming the parameter value is string (type of data).  Because I'm uncertain about this I tried using some of the functions described http://multicommander.com/docs/multiscript/corefunctions but this produced an error in the debugger saying that no such function existed.

Right now it looks like my only problem is how to find the value entered as a parameter on the command line.

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4449
    • View Profile
    • Multi Commander
Look at the "Google Search" example.. it picks up the parameters with some variables that gets auto created
$argcount and $arg[] array

The TagValue are not really used with MultiScript unless you have to. They are really created for other bat scripts and customcommands..



ajax

  • Junior Member
  • **
  • Posts: 25
    • View Profile
OK, I think I see what you mean.  However, this experience again demonstrates the need/desire to be able to test scripts that use this capability with the debugger.  When I code what is shown in your post and would have thought is correct for an array type variable (i.e., $arg[]) nothing happens which I've come to recognize as meaning there is error in the script.  When I looked closer I noticed that the "Google Search" example that you referenced actually codes it instead as "$arg()" which I found perplexing but went ahead and tried anyway.  That worked but then when I invoke the script form the command line but without an argument it fails.  Is there a suggested method for writing a script that can figure out whether or not arguments have been specified on the invoking command?  Might there be an explanation for the alternative syntax used on the $arg variable?

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4449
    • View Profile
    • Multi Commander
The debugger will log out if there are any error that the engine does not understand.
and you run the script in the debugger and it wil run line by line. and you can see all variable that the script engine has in the watch window.

MultiScript are low level. and CustomCommand the the other are high level command, they are used for different things. CustomCommand is like pressing a command  in the UI. (but with preset options) with MultiScript you can access the core function at a more core level.  MultiScritp is not connect to the UI in the same way

No you need to fake parameters while you debug. 99% of script do not actually use parameters.. they act on items in the file list. The get selected items and so on. and do things with that.



ajax

  • Junior Member
  • **
  • Posts: 25
    • View Profile
Making some progress but still hitting some snags.  Your suggestion about NOT using TagValues in multiscript is something I'm attempting to do.  Now that, I think, I've found the low level functions that do what I need I thought it would be good to change.  I believe this is also going to help with my desire to run scripts on multiple selections.  However I've experienced an anomaly that I cannot explain.

Following is a couple of lines of code that do NOT work -

@var $linkpath = GetTargetPath();
MC.Utils.CreateLink ASADMIN LNKTYPE=1 LNKTRG={$filepath} LNKSRC={$linkpath}\{$linkname}
 
However, if I change to the following it does work -

@var $linkpath = GetTargetPath();
MC.Utils.CreateLink ASADMIN LNKTYPE=1 LNKTRG={$filepath} LNKSRC=${targetpath}\{$linkname}   

Another curious point that is revealed in the debugger is that the value returned by GetTargetPath() and ${targetpath} are the same and both are strings that end with the backslash ('\') character.  However, if I remove the backslash ('\') character shown in the argument to LNKSRC that separates the 2 parts of the fully qualified path then it FAILS to work.  I would expect that after the variable substitution has occurred this would result in the double backslash ('\\') which I'd think does NOT belong there.


Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4449
    • View Profile
    • Multi Commander
Windows will ignore double slashes
But you should put " around each path, because if there are space in the path it will cut out when parsing the parameters for the custom command
Also you can build the complete path first into a variable before sending it. then you will see the difference of the complete path

Not sure why it fails. It works here., might be because of some other reason.


ajax

  • Junior Member
  • **
  • Posts: 25
    • View Profile
OK!  Following is slight change per your suggestion which DOES work -

@var $linkpath = GetTargetPath();
@var $link = $linkpath + $linkname;
MC.Utils.CreateLink ASADMIN LNKTYPE=1 LNKTRG={$filepath} LNKSRC={$link}

which while good still leaves me a bit perplexed when it comes to why.

Above was done for purpose of testing limited change but I have also added the quotes you suggested and that seems to be no problem.  So, per your point is good.

Very grateful for your help.  Well done!

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4449
    • View Profile
    • Multi Commander
OK!  Following is slight change per your suggestion which DOES work -

@var $linkpath = GetTargetPath();
@var $link = $linkpath + $linkname;
MC.Utils.CreateLink ASADMIN LNKTYPE=1 LNKTRG={$filepath} LNKSRC={$link}

which while good still leaves me a bit perplexed when it comes to why.

Above was done for purpose of testing limited change but I have also added the quotes you suggested and that seems to be no problem.  So, per your point is good.

Very grateful for your help.  Well done!

Tip
If you not really sure if you have the slash that separate the folder and name there or not..  you can use the "path append" operator ^
Code: [Select]
//instead of
@var $link = $linkpath + $linkname;
//you can use
@var $link = $linkpath ^ $linkname;

^ Will check if any of the side have a \ or /  if not, then it will add a \


ajax

  • Junior Member
  • **
  • Posts: 25
    • View Profile
Good to know.  Will do!

I also discovered that another technique that works is the following:

MC.Utils.CreateLink ASADMIN LNKTYPE=1 LNKTRG="{$filepath}" LNKSRC="{$linkpath^$linkname}"

Again.  Thanks for helping.  Multi Commander is very impressive!