iTranslated by AI
Using Power Automate Desktop as a Casual Code Scratchpad
Using Power Automate Desktop as a Casual Code Playground
Overview
Power Automate Desktop is an RPA tool for automating tasks and comes pre-installed with Windows.
After trying it out, it feels like it connects Windows features and various scripting languages much more easily than before.
I evaluated it as a handy platform because it's fun to use not just as a glue language, but also for trial and error with ideas.
While you can use it to call desktop flows from Power Automate cloud flows by installing the computer runtime, I haven't evaluated that this time.
Features
Flow Variables
They are designed so you don't have to worry about names.
The results of actions are stored in flow variables, and these variable names are assigned automatically. The naming follows a pattern for each action.
Changing them later is also easy. If you change a name from the flow variable list, all references are updated.
Furthermore, when creating a new flow, you can start without a title if you don't name it.
If you never save the flow, it won't remain, so you can test from scratch by writing code casually and choosing not to save if the idea doesn't work out.
When trying to implement a mechanism, it's not easy to come up with appropriate names from the start.
Having names automatically assigned for the time being, and then being able to change them to more suitable names once the creator understands the logic better, lowers the barrier to entry.
Scripting Languages
Various scripting languages built into Windows can be called. Additionally, Python is built-in.
The script to be executed is saved within the action, but the input field cannot be expanded, which is a point that needs improvement.
- Command Prompt
- PowerShell
- Windows Scripting Host (VBScript, JScript)
- IronPython (though it is version 2.7.9)
IronPython is Python implemented in .NET. You can call .NET features.
The Python standard library is not included in it, but it can be downloaded and added later.
Control Structures
Power Automate Desktop has a flow consisting of a sequence of actions that are executed in order.
Calling a scripting language is executed within a dedicated action. The flow cannot proceed to the next action until the script completes.
Flow control structures are also built by arranging actions. Therefore, it is not suitable for creating complex control structures.
The maximum number of actions that can be created in a single flow is limited to 500 steps.
This limit can be mitigated by creating subflows.
Robin
Scalar values for variables include numbers, strings, and booleans.
Others include tables, lists, custom objects, etc.
To embed and reference variables, you wrap them in percent signs like %NewVar%. It looks like a batch file.
The content inside % % becomes an expression and is evaluated with Robin syntax.
In addition to variable names, several operators and conditional functions equivalent to If statements can be written.
-
%'abc'%: String (same meaning asabc) -
%NewVar + 1%%NewVar - 2%%NewVar * 3%%NewVar / 4%: Arithmetic operations -
%NewVar + 'x'%: String concatenation -
%''%: String with length 0 -
%True%%False%: Boolean values
For details, see Use variables and the % notation.
Variables have types. Literals set in variables are evaluated as numeric types if they can be considered .NET Decimal numbers; otherwise, they become string types.
For example, 79228162514264337593543950335 is a numeric type, but the integer 79228162514264337593543950336, which is one greater, is interpreted as a string type because it falls outside the range representable by Decimal.
Also, E notation is not supported.
Hoisting occurs for variables defined in actions. They are initialized with default values just before they are first used.
Except for custom objects, there are no uninitialized variables.
Exceptions for custom objects can be generated by converting JSON that has properties with null values.
But accessing an uninitialized property causes a runtime error. It is not possible to determine if it is uninitialized using a function.
Variable Expansion
Even if it's not a string variable, variables in places where a string variable is expected are implicitly converted to strings.
When inserting variables into scripting language actions, it's possible to dynamically replace parts of the script, but since it's a simple string replacement, it can break the syntax.
In that sense, you need to be as careful as you would with batch file variables.
Power Automate Desktop has actions to execute SQL, and if you use variables without checking them, SQL injection can be easily achieved.
Shortcut Keys for Launching
Flows are typically executed by opening the Power Automate Desktop console and pressing the run button, but launching via keyboard combinations (shortcuts) is also supported.
If you run a flow frequently, setting up a shortcut key is practical.
Drawbacks
Long Startup Time
Flows are stored in the cloud, and they are downloaded every time before execution.
As a result, starting a flow takes a bit of time.
Sequential Execution Only
Parallel processing and asynchronous processing of actions are not possible.
Even scripting languages must wait until execution is finished.
You also cannot utilize things like pipes or streams.
Difficulty in Sharing Knowledge Between Users
Flows you've created can be copied to the clipboard with the Ctrl-C shortcut.
If you paste them into a text editor, you'll see they follow the Robin language syntax.
However, pasting these onto social media doesn't look very good.
The reason is that standard syntax highlighting doesn't support it, and manually posting screenshots every time is a lot of work.
It's unfortunate that there is no standard way to share code.
Paid Features
With premium features, it seems you can create shortcuts on the desktop or launch flows in batches via a URL.
Python Tips
Here are some tips for using it as a platform for the Python language.
Input Variables
Flow variables to be injected into a script are embedded as strings within the code.
Pass string variables by wrapping them in triple quotes. This prevents errors even if there are line breaks.
new_var = """%NewVar%"""
If there's a possibility that a string variable contains symbols, escape \ " in advance.

(Copy of the above)
Text.Replace Text: NewVar TextToFind: $'''[\\\\\"]''' IsRegEx: True IgnoreCase: False ReplaceWith: $'''\\$0''' ActivateEscapeSequences: False Result=> NewVar
To handle vector variables such as table types instead of strings, escaping symbols is required for every value.
Alternatively, saving variables to a CSV file and passing the file path—then reading the file on the Python side—reduces the effort required for escaping.
Output Variables
The content of the standard output is stored in the flow variable PythonScriptOutput.
Either output text from the Python side or output JSON and convert it to a custom object later.
Regardless of the output content, a Unicode BOM is included at the beginning of PythonScriptOutput.
This is likely because of the behavior when opening a pipe by specifying Unicode in Windows, but since it's an obstacle for post-processing, remove the first character when referencing it, like PythonScriptOutput[1:].
If there is a runtime error, the standard error output is stored in ScriptError.
Since this flow variable is not generated by default, enable it from "Variables produced" in the action settings.
Module Path
Only a few Python modules are built-in.
You can add more modules later.
For example, you can download and incorporate the IronPython standard library.
Download IronPython.StdLib.2.7.9.zip [1] and extract it to a location like C:\Python27\Lib.
By specifying the folder path in the "Module folder path" under the action's "Advanced" settings, you can use it with import.
You can also add it to sys.path within the Python script. With this method, you can even specify the .zip file directly.
import sys
sys.path.append(r"""%PythonModuleZip%""")
Discussion