Script Example - Using Notepad

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:

  1. It inserts some text in the Notepad window when Notepad starts.

  2. It shows a message to the user when the About box is shown.

  3. It automatically opens the About box after the text has been displayed.

This simple script covers all the main sections of the scripting language.

The Script Reference covers all commands in detail, along with some real world example scripts.

Note on Quotes

The desktop scripting language expects standard quote symbols (“).

Some editors, e.g. Word, substitute decorative quotes when you type in standard quote symbols.

The image below shows the effect of pasting text into Word and what it should look like.

This is the most common cause of error if copying and pasting scripts from Word or Outlook emails.

Steps in Scripting an App

Scripting a desktop app involves:

  • Creating an app template in the My1Login admin area that describes the application and holds the script.

  • Identifying the executable that starts the app.

  • Identifying those aspects of the app that are relevant to scripting, e.g. dialog boxes, controls.

  • Writing and testing the script.

Creating App Template in My1Login

In the admin / Apps area of My1Login a desktop app is defined.

The image below shows a configuration that will start the Notepad app. The Require Credentials option is cleared because we do not need to login to Notepad. Some customers make use of this option to have the Desktop Client act as a smart shortcut to apps.

The Notepad application is on the path, so no folder is required.

Starting Notepad and Writing Text

The following script starts off by being configured to stop running and warn the user if there is a runtime error.

It then starts the Notepad process, if launched from the web vault. It knows to start Notepad because bmAppPath returns the contents of the “Path to App” field from the configuration. There are similar variables available for all template and bookmark fields.

The script then waits until it detects that the process is running.

Finally the script sends some text into Notepad. This shows the use of some other configuration variables. The SendKeys command is capable of sending special command sequences to simulate the user pressing keys such as Control or Alt, etc.

OnError Terminate AlertUser

StartProcess bmAppPath
WaitProcess bmAppPath

SendKeys "Hello to " bmAppPath " from the template " bmTemplateName " (" bmTemplateDescription ")"

This produces the following output:

Responding to the About Box

We will now extend the script such that whenever the Notepad’s About Box is shown it displays a message to the user.

On opening the About Box we can see it has a tile of “About Notepad”.

In the script, below, the WhenWindow command monitors the windows desktop and, when a window comes into focus and it has the caption “About Notepad”, it runs the commands between the following {}s.

OnError Terminate AlertUser

StartProcess bmAppPath
WaitProcess bmAppPath

SendKeys "Hello to " bmAppPath " from the template " bmTemplateName " ("   bmTemplateDescription ")"

WhenWindow "About Notepad"
{
  AlertInfo "Hello from " bmTemplateName, "My1Login Desktop Message"
}

In this case a message is displayed in the notification area, as shown below:

Finally, we’ll add a command to open the About Box automatically.

Note

This command relies on the WhenWindow configuration, therefore it must appear after the WhenWindow command.

OnError Terminate AlertUser

StartProcess bmAppPath
WaitProcess bmAppPath

SendKeys "Hello to " bmAppPath " from the template " bmTemplateName " ("  bmTemplateDescription ")"

WhenWindow "About Notepad"
{
  AlertInfo "Hello from " bmTemplateName, "My1Login Desktop Message"
}

// Open the About Box
SendKeys ALT+h "a"

Note

The script uses ALT+h to open the Help menu, followed by the a character to select the About option.

    • Related Articles

    • 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 ...
    • Desktop Scripting Overview

      Purpose The My1Login Desktop Scripting language is a Domain Specific Language (Desktop DSL), targeted at controlling and responding to Windows desktop applications, with the aim of injecting user credentials that are stored in the My1Login system. It ...
    • Commenting Desktop Scripts

      The Desktop Scripting Language supports both inline and block comments. Inline Comments C# / C++ style single line comments are supported. Any text starting with two “/”s is ignored to the end of the line. Example: // This is a comment UnSelect // ...
    • Defining a Desktop App Template

      Desktop Template Definition The desktop application template is defined in the My1Login admin area (the script has been omitted from this view). Setting Explanation Name The template name, user bookmarks have their title defaulted to this value. ...
    • Desktop Client Commands

      Table of Script Commands Command Description AlertInfo / AlertError Commands to show text messages to users. BringToForeground Attempt to force the main app window to desktop’s foreground. InteractiveSelectBookmark Allows manual intervention when ...