Skip to content

Commander Script

Bashar Astifan edited this page Nov 10, 2024 · 29 revisions

About

Commander script built to expose C# functions with simple instructions, and mix them with batch script commands

made to be similar to Batch script as it will provide a GUI solution for those who need to make their scripts more easy to use.

As partial solution to avoid UWP restriction.. if your script will deal with batch script get Telnet Server from Here

Telnet

To allow the app for using telnet under localhost please run the following command in Command Prompt as Administrator

WUT Loopback (Full Version)

checknetisolation loopbackexempt -a -n=WinUniversalTool_eyr0bca9nc39y

WUT Loopback (Mini Version)

checknetisolation loopbackexempt -a -n=wut-mini-c6a2_44kb9g2z2a90y

Contents

  • Structure
  • Constants
  • Directives
  • Tricks
  • Commands

Structure

Commander use similar structure to Windows CMD with few differences:

command parm1;, param2;, param3

as you can see when you have more than parameter you have to divide them with ';,' except for the last one

some commands able to run other commands inline

So when the command contains another (internal command) the structure will be like:

command parm1;, (internal command);, param2

also you noticed that we added the internal command between '(...)'


Commands with custom ID

If the command defined with custom ID, the ID should be like:

command [customID];, param1;, param2

the reason you should add ID between '[...]' is to prevent the ID from getting replaced by it's value during the compiling, but if you want to use it's value you can place it anywhere you want without brackets.

Note: unlike batch script where [] means optional param, here in Commander means:

  • Command / Variable ID definition
  • Use the variable as object instead of value more details below at 'Storage' section

The [ID] will handle:

  • Storage object (file, folder)
  • Variable value
  • Command result
  • Timer, Process, Task

Command with custom timeout

When you see timeout parameter. means you have to enter the value in millisecond

1 Second ~ 1000 millisecond


Batch script commands

If you want to run batch script command (telnet), just write it directly

because any unrecognized command will be considered as Batch script

or you can call the script from .bat file by placing the path directly in the script (script bundle recommended in this case)


Script Extension

use .wutc for commander scripts or .wutz for script bundle


Script Comments

You can add comments inside your script like any other language

//Comment

--Comment

/*Comment*/

::Comment (like in Batch)

#Comment (like in PowerShell)


Script Conditions

The main conditions statements are is, when, else

Commander compiler support boundaries, and that will help to avoid any confusing with large code

multi level conditions strongly supported.

is condition{
//Write commands here
}else{
//Write commands here
}

the example above can be used without

is condition
//Write commands here
else
//Write commands here
end

More details available in commands list below


Script Functions

Commander support functions, and same as conditions you can also use boundaries

the main command for defining function is func, usage like:

func [functionName]{
//Commands here
}

More details available in commands list below



Constants

This list contain some important folders/values you may need:

$InstallFolder:App install location (full path)

$Assets: App assets location (full path)

$DownloadsFolder: Current downloads folder (full path)

$ScriptLocation: Script folder (full path)

$CacheFolder: App cache folder (full path)

$TempFolder: App temp folder (full path)

$LocalFolder: App local folder (full path)

$AppIcons: App icons (Windows11, XP..etc)

$AppTheme: App theme (System, Dark, Light)

$AppLang: App language (ar-AR;de-DE;en-US;es-ES;fr-FR;it-IT;fa-IR;ru-RU;el-GR;hi-IN;ja-JP;si-LK;ta-LK;tr-TR;ur-IN;zh-CH)

$CurrDateTime: Current data-time

$ScreenWidth: Screen width

$ScreenHeight: Screen height

$OutputStatus: Current status message (in-app)

$AppVer: Current app version

$DeviceType: Device type, can be the following:

  • Mobile
  • Desktop
  • Tablet
  • IoT
  • SurfaceHub
  • Xbox
  • Unknown

$Model: Current device model

$Battery: Battery level (without %) ('none' or '255' when not available)

$Build: Current system build

$Memory: Memory usage

$Host: Current device IP ('none' when not available)

$ACState: Current AC start (Online or Offline)

$Random: Random name

$FailedLinks: Failed downloads links (related to download commands)

$FailedNames: Failed downloads names (related to download commands)

$Internet: 0 or 1 (0->No internet, 1->Internet active)

$TimeTicks: Total ticks (637644400633551041)

$Time: Current data-time (8/12/2021 10:03:35 PM)

$AccX , $AccY , $AccZ: Accelerometer Reading - (use round:$AccX to get short value)

$GyrX , $GyrY , $GyrZ: Gyrometer Reading - (use round:$AccX to get short value)

Accelerometer & Gyrometer required sensors directive (read about directives below)

$Key: Current keyboard key [keyboard directive required]

$ScriptID: will be replace by current script ID



Directives

Directives will inform the compiler with important instructions before starting the script

They Need to be in the first 3 lines of the script without any empty lines between them...otherwise they will be ignored

directives can be in one line like:

directive1,directive2,..

Directives List

notelnet: Ignore telnet connection

backw: Allow the script to run in background

noclean: Prevent the script remove by the clean button

sensors: Activate sensors values

keyboard: Activate keyboard values



Tricks

There is few options will allow you to avoid UWP restrictions and get more advanced usage

Script Bundle

As UWP will prevent any access outside the LocalData folder

you cannot use any command that required direct path without picking the file

So this feature will help you to avoid that.

Create script bundle

First: The main script should be named 'main.wutc' or the script will not work (You will get error 'No script entry found')

  1. Compress your script + other contents as zip, 7z or rar (The files not the parent folder)

  2. Change the extension to .wutz

  3. You are ready to run the script with all it's libraries

Note: Password protected scripts supported (Only for ZIP legacy encryption)

Explain: Commander will move the script and extract the files to TemporaryFolder and start it from there


Script Update

As your script may subject to improvements and fixes, update command made to make your script able to be updated

Commander will ask if the user want to update or not in case of any change

the update will work for both normal and bundled scripts

for bundled scripts you can update only main.wutc

EXAMPLE:

just place update command along with script link anywhere in your script and when the compiler reach to it, will processed with update checkup

update https://.....scripturl.....


Targeting

You can use mintarget command in your script so it will break if the app version is less

EXAMPLE:

mintarget 1.2.0


Debug

If you are new in Commander you may stuck in few places, debug mode made to give you detailed output so you can easily solve any issue

EXAMPLE:

debug state

state: 0 (no debug) - 1 (debug) enabled

Debug logs will be stored in downloads folder, if not assigned will be stored in local folder

You can also activate telnet log from WUT Settings->Telnet->Telnet Log


Startup Scripts

If you want to start some scripts with the app startup:

  1. Create new folder inside Downloads Folder called 'Startup'

  2. Put the scripts inside it

  3. Done, the scripts will run once the app startup

Note: Downloads folder means the one that selected by the user in WUT settings and NOT Windows Downloads folder


Replace Sensitive

You can switch the replace case sensitive during the script by using

rcase state

default state is match

EXAMPLE:

rcase ignore

Now Commander will replace any match and ignore the case of the letter

try always to avoid using similar ids:

if we have [urlArea] and [UrlAreaInput] when rcase is ignore

[UrlAreaInput] will get replace by half [UrlAreaInput]

to reset to the default state:

rcase match



Storage

Commander has it's own cache storage, when you call files / folders picker it will cache the request for future usage

also any defined variable will be cached.

The cache will be global can be used by multiple script

there is two ways to clean the cache:

  • call clear all command at the top of the script after directives (or clean all)

  • Close WUT.


Files / Folders

You will be confused for the first time about the deference between variableID and [variableID]

  • variableID means you need to use the variable value as string / number / path ..etc

  • [variableID] means you want to deal with the variable as object and use more advanced options

for files and folders in many commands you need to pass the file/folder ID as object [variableID]

I have made many solutions to make it easy to use, so there will be some alternate options to call command on file/folder by it's path and commander will search for it in cache storage and deal with it as object.


Note: You cannot deal with files/folders with direct path without calling file/folder picker it's UWP security restrictions

Exception 1: You will be able deal with the files/folders with direct path through telnet (batch script)

Exception 2: Bundled scripts can help you to solve the access if your script contains multiple files.

Constants: You can use any location constant as object like [$ScriptLocation] if you want to use it in advanced commands.


Strings

Commander based on direct text replacement, so you may get into some issue if you tried to use multiple lines text in some commands.

Example:

  • You may get large content from file or response
  • You need to use is to check if the file contains x value

Wrong usage (it will break the compiling):

is fileContents~~x{

}

Correct usage:

is [fileContents]~~x{

}

as you see, we inform Commander to get [fileContents] from cache storage and deal with it's value internally without placing the value into the runtime output.



Click Here to view commands