How to create a popup menu based on condition - "How-to"

studio

#1

I hope this will help someone. Here I am using AutoHotkey by “Start Process”, and not by “Run Auto Hotkey Script” or “Invoke Code.” An advantage for me of doing it this way is that “Start Process” provides an easy way to pass arguments, something I have struggled with usin “Run Auto Hot Key Script.” As written, it requires AutoHotkey to be installed. I have tested it with AutoHotkey_L and AutoHotkey_H, both 32-bit and 64-bit versions.

It requires the AutoHotkey library files “PUM.ahk” and “PUM_API.ahk”, which are included. The test AHK script, also included, is “PUMtest2.ahk”. The main workflow is “Trigger PUM on condition.xaml”, which invokes “PUM workflow extracted.xaml.” The main workflow is quick-and-dirty, spaghetti-ish and is only intended to show the possibilities of the popup menus.

All the files provided must be in the same directory. You will have to change the paths for the scripts in the “Start Process” activity in the invoked workflow file that starts “PUMtest2.ahk”. As provided, it is "“C:\Users\Winter\Documents\UiPath\AutoHotkey experiments\Scripting and Invoking\PUMtest2.ahk”, which is guaranteed not to work for you! Use whichever folder you copied all the files to - if that doesn’t work, please let me know.

PUM and PUM_API are the brainchild of AHK user “Deo” (see PUMtest2.ahk for URL of original topic).

Objective: When some specific trigger event occurs, generate a reasonably attractive popup menu, as shown:

PopUpMenusPopUp2PopUp3

Eventually, I will (hopefully) use the popup menu items to invoke other workflows or start other robots.
Thanks for looking!
Regards,
burque505

PUM test files for UiPath.zip (19.4 KB)

Edit:: By adding a few lines of code for each robot or program to be run and commenting out some cruft in the example, I am able to run both robots and programs from a popup menu. Here is some code to experiment with, changing directory names and robot names (i.e. ‘C:\Robots’ to wherever your robot scripts are, and ‘Robot1 and Robot2’ to the names of your UiRobot scripts) as required:

Add these lines below line 61 of PUMtest2.ahk:

menu.Add( { "name" : "Run MS Word"
        , "bold" : 1
        , "icon" : "shell32.dll:112" } )
menu.Add( { "name" : "Run Notepad"
        , "bold" : 1
        , "icon" : "shell32.dll:112" } )

Comment out or delete line 79:
;msgbox % "Choosen item: " item.name

At the very bottom, replace the appropriate section [PUM_out( msg, obj )] with:
PUM_out( msg, obj )
{
if ( msg = “onselect” )
{
rect := obj.GetRECT()
CoordMode, ToolTip, Screen
;tooltip,% "Selected: " obj.name,% rect.right,% rect.top
}
if ( msg ~= “oninit|onuninit|onshow|onclose” )
tooltip % "menu " msg ": " obj.handle
if ( msg = “onrbutton” )
tooltip % "Right clicked: " obj.name
if ( msg = “onmbutton” )
tooltip % "Middle clicked: " obj.name
if ( msg = “onrun” )
;tooltip % "Item run: " obj.name
if (obj.name = “Run DA”)
{
;Msgbox, Switching to 'Robot1’
Run "C:\Robots\Robot1"
ExitApp
}
else if (obj.name = “Run Robot2”)
{
;Msgbox, Switching to 'Robot2’
Run "C:\Robots\Robot2"
ExitApp
}
else if (obj.name = “Run Notepad”)
{
;Msgbox, Switching to 'AWS Login’
Run Notepad.exe
ExitApp
}
else if (obj.name = “Run MS Word”)
{
;Msgbox, Switching to 'AWS Login’
Run Winword.exe
ExitApp
}
}
Here’s how my popup menu looks after those changes:

New menu

Since the programs are being started from AHK, the process is lightning fast. And AHK unloads when the robot is run or the program is started. Autohotkey eats up a little over 1MB of memory, and the scripts are tiny.

If this is of use to anyone, please let me know. My next experiment will be to dynamically add menu items from a spreadsheet or data table. I’ll post that (if and) when I have some luck.


Human Computer Process Interaction for Back Office Robots
#2

Wow @burque505 thanks for the information. I have one question for you is this related to AWS, I yes is this related to AWS Certification

Thanks In Advance
SarahJohn


#3

@Sarah_Johan, the reference in the menus – commented-out code in an AutoHotkey script – is to an Amazon Web Services login session from which the code was cloned, not to the AWS training link you provided.
Regards,
burque505