Examples

Here you will find some example scripts to give you an idea on using the shell.

Recursive function call

# Demonstrate recursive function calls

const MAX_COUNT int <= 10;

function recursive void(count int)
{
  if (%count, -ls, %MAX_COUNT) {
    ++ count;
    print "Count value: %count";
    call recursive(%count) => void;
  };
};

call recursive(0) => void;

print "Done.";

pause;

Run Windows dialog to set time and date

# Run timedate.cpl

function clock void() {
    sys { timedate.cpl };
};

call clock() => void;

Get Internet IP address from a service

# Get Internet IP address of this machine

const SERVICE_URL string <= "https://www.example.tld/ip.php";

global ipaddr string;

sys {curl "%SERVICE_URL" --silent} ipaddr;

print "IP address: %ipaddr";

Upgrade composer dependencies of various projects

# Upgrade composer dependencies

require "array";
require "auto";

array arrProjects string 5 (
    "public_html/project-1", 
    "public_html/project-2",
    "public_html/project-3",
    "public_html/project-4",
    "public_html/project-5"
);

function upgrade_dependencies void(folder string)
{
    print "Upgrading %folder...";
    
    aut_run "composer" "update --working-dir %folder" "%folder" void;
};

print "Upgrading projects...";

for (i, 0, %arrProjects.length, -inc) {
    call upgrade_dependencies(%arrProjects[%i]) => void;
};

print "Done.";

Generate a testing password via external program

# Quickly generate BCRYPT password via PHP

require "strings";
require "auto";

const C_TEST_PASSWORD string <= "test";

global expression string;
global exprlen int;

set expression <= "%2";

s_getlen "%expression" exprlen;
if (%exprlen, -ls, 3) {
    set expression <= "%C_TEST_PASSWORD";
};

if ("%2", -eq, "--verbose") {
    print "Generating password for: %expression";
};

function genenrate_password void()
{
    local output string;
    
    sys {php -r "echo password_hash('%expression', PASSWORD_BCRYPT);"} output;
    print "%output";
    
    aut_clpbsetstring "%output";
    print "Copied to clipboard!";
};

call genenrate_password() => void;

if (%DNYAS_IS_INTERACTIVE_MODE, -eq, false) {
    pause;
};

Parse commandline arguments of a script

# Commandline argument parser

function cmd_has bool(search string)
{
    result false;

    if (%argc, -gr, 1) {
        for (i, 1, %argc, -inc) {
            if ("%argv[%i]", -eq, "%search") {
                result true;
            };
        };
    };
};

function cmd_pair string(key string)
{
    result "";

    if (%argc, -gr, 1) {
        for (i, 1, %argc, -inc) {
            if ("%argv[%i]", -eq, "%key") {
                local varIncr int;

                set varIncr <= %i;
                ++ varIncr;

                if (%varIncr, -ls, %argc) {
                    result "%argv[%varIncr]";
                };
            };
        };
    };
};

Show environment variables via GUI

# Show environment variables via GUI

require "strings";
require "forms";

global frmMain int;
global bres bool;
global envcont string;

wnd_spawnform "frmMain" "Windows Environment Variables" 200 300 500 350 frmMain;

wnd_isformvalid frmMain bres;

if (%bres, -eq, false) {
    print "Failed to create form.";
    pause;
    exit;
};

wnd_spawnlistview "frmMain" "lvVariables" 10 10 467 295;
wnd_lvaddcategory "frmMain" "lvVariables" "Name" 225 true;
wnd_lvaddcategory "frmMain" "lvVariables" "Value" 220 true;

sys {set} envcont;

s_tokenize "%envcont" "%CR%LF" splittedvars;

global szVarName string;
global szVarValue string;
global numTokenIndex int;

for (i, 0, %splittedvars.count, -inc) {
    s_find "%splittedvars[%i]" "=" numTokenIndex;
    
    if (%numTokenIndex, -gr, 0) {
        s_substr "%splittedvars[%i]" 0 %numTokenIndex szVarName;

        ++ numTokenIndex;
        s_substr "%splittedvars[%i]" %numTokenIndex -1 szVarValue;

        wnd_lvsetitemtext "frmMain" "lvVariables" "%szVarName" 0 bres;
        wnd_lvsetsubitemtext "frmMain" "lvVariables" 0 "%szVarValue" 1 bres;
    };
};

while (%bres, -eq, true) {
    wnd_process;

    wnd_isformvalid frmMain bres;
};

Check if internet is available

# Check if internet is available

require "array";
require "strings";

array arrDomains string 3 (
    "https://www.google.com", 
    "https://www.microsoft.com", 
    "https://store.steampowered.com"
);

global checkresult bool;

function check_availability bool(domain string)
{
    local response string;
    local httprespos int;

    result false;

    print "Checking via domain: %domain";

    sys {curl "%domain" -X HEAD -I --silent} response;

    s_find "%response" "HTTP/1.1 200 OK" httprespos;
    
    if (%httprespos, -eq, 0) {
        result true;
    };
};

global resultcount int;
set resultcount <= 0;

for (i, 0, %arrDomains.length, -inc) {
    call check_availability("%arrDomains[%i]") => checkresult;

    if (%checkresult, -eq, true) {
        ++ resultcount;
    };
};

if (%resultcount, -gr, 0) {
    print "Internet is available (%resultcount/%arrDomains.length succeeded).";
} else {
    print "All connection attempts failed.";
};

if (%DNYAS_IS_INTERACTIVE_MODE, -eq, false) {
    pause;
};

Speak text entered via GUI input box

# Speak text entered via GUI input box

require "input";
require "speech";

global inputspeakrun bool;
set inputspeakrun <= true;

global slastphrase string;
set slastphrase <= "Hello World!";

spk_setvoice "Microsoft Zira Desktop";
spk_setvolume 100;

function prompt_and_speak void()
{
    local text string;

    inputbox "Speech Prompt" "Enter a text to speak" "%slastphrase" 700 500 text;
    
    if (%text, -nt, "") {
        set slastphrase <= "%text";
        spk_speakasync "%text";
    } else {
        set inputspeakrun <= false;
    };
};

while (%inputspeakrun, -eq, true) {
    call prompt_and_speak() => void;
    sleep 10;
};

unset inputspeakrun;
unset slastphrase;

Heroes of the Storm Chat Hotkeys

# Send chat messages to Heroes of the Storm via hotkeys
#
# This script features binding chat messages to the keys F5, F6, F7, F8 and F9 by default.
# Key F5 - F8 are subject to single chat messages where key F9 will be subject to a switching
# toggle. That means you can specify a dynamic amount of chat messages that will be iterated on
# and once the end is reached, it will be starting over from the beginning again.

# You can edit the chat messages via the GUI (except switching toggles). The script does also check
# if the current foreground window is the window of the game in order to prevent that the chat messages 
# are inserted elsewhere.
#
# Chat messages are stored in the text file defined via the constant CONFIG_NAME. If it does not exist
# then the script will create a sample file that can be edited afterwards.
#

require "array";
require "auto";
require "fileio";
require "forms";
require "strings";

const WND_CLASS string <= "Heroes of the Storm";
const CONFIG_NAME string <= "hots_messages.txt";
const FORM_TEXT string <= "HotS Chat Hotkey Manager";
const KEY_CODE_1 int <= 116; #F5
const KEY_CODE_2 int <= 117; #F6
const KEY_CODE_3 int <= 118; #F7
const KEY_CODE_4 int <= 119; #F8
const KEY_CODE_5 int <= 120; #F9
const CONFIG_TOGGLE_SECTION_START int <= 4;

global bres bool;
global brun bool;
global currentpath string;
global configpath string;
global keytoggle1 bool;
global keytoggle2 bool;
global keytoggle3 bool;
global keytoggle4 bool;
global keytoggle5 bool;
global switchcount int;
global switchmsg string;
global lasttimeactive bool;

set bres <= false;
set brun <= true;
set currentpath <= "";
set configpath <= "";
set keytoggle1 <= false;
set keytoggle2 <= false;
set keytoggle3 <= false;
set keytoggle4 <= false;
set keytoggle5 <= false;
set switchcount <= %CONFIG_TOGGLE_SECTION_START;
set switchmsg <= "";
set lasttimeactive <= true;

array arrConfigItems string 0 ();

getscriptpath currentpath;

set configpath <= {%currentpath%CONFIG_NAME};

function GameWindowActive bool()
{
    local targetwnd int;
    local wndfg int;

    result false;
    
    aut_findwindow "%WND_CLASS" \0 targetwnd;
    
    if (%targetwnd, -gr, 0) {
        aut_getfgwindow wndfg;
        
        if (%wndfg, -eq, %targetwnd) {
            result true;
        };
    };
};

function cbHotKeyToggles_OnSelect void(newItem string)
{
};

function btnSaveMessages_OnClick void()
{
    local currentitem string;
    local checkexists bool;
    local hfile int;
    local fopres  bool;

    wnd_gettextboxtext frmMain txtMsg1 currentitem;
    store_item_to_array "currentitem" arrConfigItems 0;

    wnd_gettextboxtext frmMain txtMsg2 currentitem;
    store_item_to_array "currentitem" arrConfigItems 1;

    wnd_gettextboxtext frmMain txtMsg3 currentitem;
    store_item_to_array "currentitem" arrConfigItems 2;

    wnd_gettextboxtext frmMain txtMsg4 currentitem;
    store_item_to_array "currentitem" arrConfigItems 3;

    set checkexists <= true;

    fexists "%configpath" checkexists;
    if (%checkexists, -eq, true) {
        fremove "%configpath" fopres;
    };
    
    fopen "%configpath" true hfile;
    if (%hfile, -nt, %FIO_INVALID_HANDLE) {
        for (i, 0, %arrConfigItems.length, -inc) {
            if ("%arrConfigItems[%i]", -nt, "") {
                fwriteline %hfile "%arrConfigItems[%i]";
            };
        };
        
        fclose %hfile;
    };

    print "Saved chat messages to: %configpath";
};

function btnExitScript_OnClick void()
{
    wnd_freeform frmMain;
};

function LoadMessages void()
{
    local filecontent string;
    local chatcfgexists bool;
    local cntnumber int;

    fexists "%configpath" chatcfgexists;
    if (%chatcfgexists, -eq, false) {
        sys {echo -= Go0d Luck ^& Have Fun =->>"%configpath"};
        sys {echo -= ! G0od Game ! =->>"%configpath"};
        sys {echo -= NiCe jOb =->>"%configpath"};
        sys {echo -= Let us rush the core =->>"%configpath"};
        sys {echo -= Please add more switching messages =->>"%configpath"};
    };

    sys {type "%configpath"} filecontent;

    s_tokenize "%filecontent" "%CR%LF" splittedmsgs;
    
    item_insert arrConfigItems 0 "%splittedmsgs[0]";
    item_insert arrConfigItems 1 "%splittedmsgs[1]";
    item_insert arrConfigItems 2 "%splittedmsgs[2]";
    item_insert arrConfigItems 3 "%splittedmsgs[3]";
    
    if (%splittedmsgs.count, -gre, %CONFIG_TOGGLE_SECTION_START) {
        for (i, %CONFIG_TOGGLE_SECTION_START, %splittedmsgs.count, -inc) {
            item_insert arrConfigItems %i "%splittedmsgs[%i]";
        };
    };

    set cntnumber <= %splittedmsgs.count;
    -= cntnumber 4;

    set switchmsg <= "(You have %cntnumber switching items)";
};

function CreateWindow void()
{
    local cbselindex int;

    wnd_spawnform frmMain "%FORM_TEXT" 500 400 635 330 bres;

    wnd_spawnlabel frmMain "lblKey1" 20 10 20 30 "F5: ";
    wnd_spawnlabel frmMain "lblKey2" 20 50 20 30 "F6: ";
    wnd_spawnlabel frmMain "lblKey3" 20 90 20 30 "F7: ";
    wnd_spawnlabel frmMain "lblKey4" 20 130 20 30 "F8: ";
    wnd_spawnlabel frmMain "lblKey5" 20 170 20 30 "F9: ";
    
    wnd_spawntextbox frmMain "txtMsg1" 50 10 550 20 "";
    wnd_spawntextbox frmMain "txtMsg2" 50 50 550 20 "";
    wnd_spawntextbox frmMain "txtMsg3" 50 90 550 20 "";
    wnd_spawntextbox frmMain "txtMsg4" 50 130 550 20 "";
    wnd_spawncombobox frmMain "cbHotKeyToggles" 50 170 550 1500;

    wnd_spawnlabel frmMain "lblWndStatus" 20 215 350 30 "";

    wnd_spawnbutton frmMain "btnSaveMessages" 20 255 200 30 "Save";
    wnd_spawnbutton frmMain "btnExitScript" 400 255 200 30 "Exit";

    wnd_settextboxtext frmMain txtMsg1 "%arrConfigItems[0]";
    wnd_settextboxtext frmMain txtMsg2 "%arrConfigItems[1]";
    wnd_settextboxtext frmMain txtMsg3 "%arrConfigItems[2]";
    wnd_settextboxtext frmMain txtMsg4 "%arrConfigItems[3]";
    
    for (cbcnt, %CONFIG_TOGGLE_SECTION_START, %arrConfigItems.length, -inc) {
        wnd_cbadditem frmMain cbHotKeyToggles "%arrConfigItems[%cbcnt]";
    };

    wnd_cbgetcount frmMain cbHotKeyToggles cbselindex;

    wnd_cbadditem frmMain cbHotKeyToggles "%switchmsg";
    wnd_cbselectitem frmMain cbHotKeyToggles %cbselindex;
};

function SendText void(texttosend string)
{
    local kres bool;

    print "Sending text: %texttosend ...";
    
    aut_sendkeystrokes {\VK_RETURN;} false false false kres;
    sleep 1;
    
    aut_sendkeystrokes %texttosend false false false kres;

    sleep 1;
    aut_sendkeystrokes {\VK_RETURN;} false false false kres;
};

function CheckKey1 void()
{
    local kdres bool;
    
    aut_iskeydown %KEY_CODE_1 kdres;
    
    if (%kdres, -eq, true) {
        if (%keytoggle1, -eq, false) {
            call SendText("%arrConfigItems[0]") => void;
        
            set keytoggle1 <= true;
        };
    } else {
        if (%keytoggle1, -eq, true) {
            set keytoggle1 <= false;
        };
    };
};

function CheckKey2 void()
{
    local kdres bool;
    
    aut_iskeydown %KEY_CODE_2 kdres;
    
    if (%kdres, -eq, true) {
        if (%keytoggle2, -eq, false) {
            call SendText("%arrConfigItems[1]") => void;
        
            set keytoggle2 <= true;
        };
    } else {
        if (%keytoggle2, -eq, true) {
            set keytoggle2 <= false;
        };
    };
};

function CheckKey3 void()
{
    local kdres bool;
    
    aut_iskeydown %KEY_CODE_3 kdres;
    
    if (%kdres, -eq, true) {
        if (%keytoggle3, -eq, false) {
            call SendText("%arrConfigItems[2]") => void;
        
            set keytoggle3 <= true;
        };
    } else {
        if (%keytoggle3, -eq, true) {
            set keytoggle3 <= false;
        };
    };
};

function CheckKey4 void()
{
    local kdres bool;
    
    aut_iskeydown %KEY_CODE_4 kdres;
    
    if (%kdres, -eq, true) {
        if (%keytoggle4, -eq, false) {
            call SendText("%arrConfigItems[3]") => void;
        
            set keytoggle4 <= true;
        };
    } else {
        if (%keytoggle4, -eq, true) {
            set keytoggle4 <= false;
        };
    };
};

function CheckKey5 void()
{
    local kdres bool;
    local fixcount int;

    set fixcount <= %arrConfigItems.length;
    -- fixcount;
    
    aut_iskeydown %KEY_CODE_5 kdres;
    
    if (%kdres, -eq, true) {
        if (%keytoggle5, -eq, false) {
            call SendText("%arrConfigItems[%switchcount]") => void;
            
            ++ switchcount;
            if (%switchcount, -gre, %fixcount) {
                set switchcount <= %CONFIG_TOGGLE_SECTION_START;
            };
        
            set keytoggle5 <= true;
        };
    } else {
        if (%keytoggle5, -eq, true) {
            set keytoggle5 <= false;
        };
    };
};

function UpdateGameWindowStatus void()
{
    local iswndactive bool;
    local wndstatusmsg string;

    call GameWindowActive() => iswndactive;
    if (%iswndactive, -eq, true) {
        if (%lasttimeactive, -eq, false) {
            set wndstatusmsg <= "window found in foreground!";

            wnd_setcomptext "frmMain" "CLabel" "lblWndStatus" "Game Status: %wndstatusmsg";
            print "Game Status: %wndstatusmsg";

            set lasttimeactive <= true;
        };
    } else {
        if (%lasttimeactive, -eq, true) {
            set wndstatusmsg <= "window not in foreground...";

            wnd_setcomptext "frmMain" "CLabel" "lblWndStatus" "Game Status: %wndstatusmsg";
            print "Game Status: %wndstatusmsg";

            set lasttimeactive <= false;
        };
    };
};

call LoadMessages() => void;
call CreateWindow() => void;

print "%FORM_TEXT%CR%LF";

while (%brun, -eq, true) {
    call CheckKey1() => void;
    call CheckKey2() => void;
    call CheckKey3() => void;
    call CheckKey4() => void;
    call CheckKey5() => void;

    call UpdateGameWindowStatus() => void;

    wnd_process;
    wnd_isformvalid frmMain brun;

    sleep 1;
};