Introductory Script Example

Introductory Script Example

This section describes a sample Windows application and shows how the My1Login desktop scripting language may be used to interact with it.

This example is contrived, but it covers the features used by the majority of scripts.

Sample Application

My1Login developed a simple windows application to demonstrate the scripting language.

The following images show the app and describe its use.

The main app window, the user is logged out.

The user may login by either clicking on the “Login…” button or selecting the File / Login menu option. Whereupon they are presented with a login dialog.

Login Dialog

User Logged In

About Box

The About Box has a text field that contains the name of the logged in user and two buttons that differ by the username on them.

Clicking the “Option” buttons shows a pop-up that states which button was pressed. These buttons are used to demonstrate selecting controls based upon other screen content.

“Option Arthur” Clicked

“Option Klara” Clicked

Complete Script

The full script is shown here for completeness, followed by a line by line analysis.

OnError Terminate AlertUser

StartProcess bmAppPath bmAppArgument
WaitProcess bmAppPath

AlertInfo "Username is " bmUsername , bmTitle

// Open the login form
SendKeys ALT+f "l" bmUsername TAB bmPassword ENTER

WhenWindow "About ACME CMS" ControlStatic "klara"
{
       AlertInfo "Klara"
       Select ControlButton "klara"
       SendKeys ENTER
}

WhenWindow "About ACME CMS" ControlStatic "arthur" EveryTime
{
       AlertInfo "Arthur"
       Select ControlButton EndsWith "arthur"
   // Click on the centre of the button
       LeftClick HorizontalMiddle VerticalMiddle
}

Template Definition

The desktop application template is defined for this app in the My1Login admin area (the script has been omitted from this view).

See Desktop Template Definition for details.

Script Walk Through

This script does not contain a SelectBookmark command, therefore it will follow the default behaviour of:

  • If the user launched the app from a web vault tile then the credentials of that tile are used, otherwise:

  • If there is only one bookmark for the app then its credentials are used.

  • If there are multiple bookmarks for the app the user is presented with a list of usernames and asked to select the one to use.

OnError Terminate AlertUser

If an error is encountered the script execution is stopped and the user informed of the error.

StartProcess bmAppPath bmAppArgument

Starts the application, passing the path and command line arguments from the bookmark template.

If the application is started by the user on their desktop then this command is ignored.

If the bmAppPath contains a “Program Files (x86)” folder, for a 64 bit OS, but the script is being executed on a 32 bit OS then the folder name is automatically changed to “Program Files”.

WaitProcess bmAppPath

Pauses the running of the script until a process, whose name or path matches the parameter, is the foreground window. The usual pattern is to simply wait on the startup path. However this isn’t always applicable, see the WaitProcess for details.

If the bmAppPath contains a “Program Files (x86)” folder, for a 64 bit OS, but the script is being executed on a 32 bit OS then the folder name is automatically changed to “Program Files”.

AlertInfo "Username is " bmUsername , bmTitle

Pop-up a notification informing the user that the app has been detected and which username will be logged in.

SendKeys ALT+f "l" bmUsername TAB bmPassword ENTER

The above SendKeys command logs the user in:

ALT+f "l"

  • Selects the File menu (Alt key and f key together)

  • Then selects the Login item (short cut key is letter L)

  • The login dialog automatically sets focus on the username field, so we start from there

bmUsername TAB bmPassword ENTER

  • Types the username into the username field

  • Presses TAB to move to the password field

  • Types the password into the password field

  • Presses Enter key to complete the login

WhenWindow "About ACME CMS" ControlStatic "klara"

WhenWindow defines a block of script commands to run when the About Box (with caption “About ACME CMS”) is shown and any of the basic text controls contain the text “klara” (not case sensitive).

The about box shows the username, so this WhenWindow will trigger if the user “klara” is logged in.

This configuration of WhenWindow will only trigger once after the About Box is opened and gains focus. Moving away from and back to the About Box will not trigger the code a second time. The later example shows how to have the WhenWindow triggered every time the About Box comes into focus.

{
 AlertInfo "Klara"

Pops up a message to the user with the text “Klara” in it.

Select ControlButton "klara"

Sets the input focus to the button that contains the text “klara”.

SendKeys ENTER

Presses the Enter key which clicks the selected button, this pops up the dialog shown above indicating that the Option Klara was selected.

}

WhenWindow "About ACME CMS" ControlStatic "arthur" EveryTime

As before, this configures a block of script to run when the About Box is in the foreground and one of the text controls contains the value “arthur”.

The about box shows the username, so this WhenWindow will trigger if the user “arthur” is logged in.

Unlike the previous WhenWindow this instance has the EveryTime option. This means that the WhenWindow script will run everytime the About Box is brought into focus.

{
  // Pops up a message to the user
  AlertInfo "Arthur"

  Select ControlButton EndsWith "arthur"

Sets the input focus to the button that ends with the text “arthur”

This time, rather than using the Enter key to press the “Option Arthur” button we will us a mouse click.

LeftClick HorizontalMiddle VerticalMiddle

Sends a left mouse click to the previously selected button.

The HorizontalMiddle and VerticalMiddle refer to the currently focused control, so this places the mouse cursor at the centre of the button before the click is sent.

The mouse cursor is returnd to its starting point once this action is complete (otherwise the user would be confused due to the unexpected mouse change of location).

}
    • Related Articles

    • Introductory Script Example

      This section describes a sample Windows application and shows how the My1Login desktop scripting language may be used to interact with it. This example is contrived, but it covers the features used by the majority of scripts. Sample Application ...
    • Advanced Script Examples

      Remote Desktop / Windows Credential Dialog /***************** * Remote desktop script (mstsc.exe, not windows 10 one) * * The Enc1 field on the user's bookmark contains the target server name:port * The users need to be told to fill this in. **** * ...
    • Script Example - Using Notepad

      Script Example - Using Notepad This section introduces a basic script that interacts with the windows Notepad application. The script does three things: It inserts some text in the Notepad window when Notepad starts. It shows a message to the user ...
    • Error Directive, Alerting & Logging Commands

      OnError Controls the processing of a script in the event of a runtime error. Multiple OnError commands may be used to control behaviour at different points in the script. Syntax Diagram Parameters Terminate - stop script execution Continue - continue ...
    • Desktop Scripting

      Structure of a Script A Desktop DSL Script has the following functional sections (not all are required for all apps): Error Directive Determines the impact of errors on the script run. Process Start and Identification Ensures the correct windows ...