Lare2 wrote:Also i see you put parenthesis in Sub(""); which the syntax examples on the help doesn't mention. Any reason at all, or the help file is outdated.
Well the parenthesis are just syntactical sugar which in my opinion makes the scripts more legible, but judging from some of the shared examples I may be in the minority. They aren't required. The quotes around arguments may not be required but I always feel safer with them.
Lare2 wrote:I'm going to take a look at Global() on the wiki to see what i can come out with. But could you explain to me how would you approach it.
Well it's a mixed bag as to which is better here but for example you could do it as:
Code: Select all
/*------------------------------------------------------------------------------
This script is the default entry point.
------------------------------------------------------------------------------*/
"Main"
Sub("_setPaths"); //Declare and set the global vars.
Load("*", "_clip;_curItem"); //Load the desired menu, which can now use the global vars.
/*------------------------------------------------------------------------------
This script sets the global variables to be used by other WGET SCRIPTS.
------------------------------------------------------------------------------*/
"_setPaths"
Global $wget, $target;
$wget = <xypath>\wget\wget; // WGET EXE PATH
$target = C:\Saves; // TARGET DOWNLOAD FOLDER
/*------------------------------------------------------------------------------
WGET SCRIPT NUMBER 01
This script will download the URL on the clipboard
WGET ARGUMENTS = run """cmd"" /k ""[WGET PATH]"" --directory-prefix=[TARGET PATH] [URL]"
------------------------------------------------------------------------------*/
"Download File On Clipboard : _clip"
Global $wget, $target;
msg Would you like to download the following <br><br> <clipboard>, 1; // CONFIRM URL TO DOWNLOAD WITH MESSAGE BOX
run """cmd"" /k ""$wget"" -c --directory-prefix=$target <clipboard>"; // WGET COMMAND ARGUMENTS
/*------------------------------------------------------------------------------
WGET SCRIPT NUMBER 02
This script will attempt to download a series of links from a TXT file.
------------------------------------------------------------------------------*/
"Download From Links On Selected File : _curItem"
Global $wget, $target;
$linktxt = readfile(<curitem>);
msg The following files will be downloaded <br><br>$linktxt, 1;
run """cmd"" /k ""$wget"" -c --directory-prefix=$target --input-file=<curitem>";
To your original scripts I assigned labels (_clip & _curItem) and make them hidden from the default menu. I've also removed the calls to Sub("_setPaths") that I previously put in.
Left my "_setPaths" alone and added a new script "Main" which is the default shown when displaying the menu or executing the resource.
"Main" calls "_setPaths" which declares the vars as global and assigns the values.
Then "Main" uses Load to call the current script but by stating the labels it displays your two scripts in a menu.
The user makes their selection and after running the Global command, your scripts now see the value of the global vars.
I feel you gain some clarity over calling Sub("_setPaths") in every script that would use them, and you have better control over the displayed menu (for instance you could hide_curItem or skip the menu if no item is selected).
But you can't as easily call just one of your scripts from another source (UDC, CKS, etc.) as the paths won't get set; you'd instead have to call _setPaths first. That said if you are only putting this in a CTB that shouldn't matter as I don't think you can call the script from anywhere else (at least not as a script).