LibreAutomate

repository·master·Indexed 43 days ago

https://github.com/qgindi/libreautomate

A Windows-focused automation ecosystem built on .NET 10, featuring a C# library for UI and system automation and a dedicated script editor. It provides tools for UI automation, system management, hotkeys, autotext, and custom UI elements like toolbars and dialogs. The ecosystem includes a script editor with Intellisense, a debugger, and recording tools for keyboard/mouse input and UI objects.

Tokens
30.7K
Snippets
64
Records
164
Agent score
55%

What's inside LibreAutomate

  1. Overview of LibreAutomate

    master

    LibreAutomate is a C# script editor and library designed for automating tasks on Windows. It allows developers to automate desktop and web UIs using keyboard, mouse, and API interactions. The platform supports finding and clicking buttons, links, and images, as well as managing files, windows, and programs.

    Key capabilities include:

    • UI Automation: Find and interact with UI elements (buttons, links, images).
    • Triggers: Implement hotkeys, autotext (auto-replace/expand), and window-based triggers.
    • Custom UI: Create custom toolbars (attachable to windows or screen edges), menus, and complex dialog windows.
    • Extensibility: Use the full power of C#, .NET, NuGet libraries, and the Windows API.
    • Deployment: Create independent .exe programs or .dll libraries.
    • Development Tools: Includes a C# code editor with IntelliSense, a script manager, a cookbook, a debugger, and tools for recording keyboard/mouse input.
  2. Overview of LibreAutomate features

    master

    LibreAutomate is a C# script editor and automation library for Windows built on .NET 10. It provides two primary ways to interact with the system:

    Automation Library

    • UI Automation: Automate desktop and web interfaces using keyboard, mouse, or API. Supports finding and clicking buttons, links, and images.
    • System Management: Launch programs, manage files/windows, and process text/data.
    • Triggers & Input: Implement hotkeys, autotext (auto-replace/expand text while typing), auto-close windows, and key remapping.
    • UI Customization: Create custom toolbars (attachable to windows or screen edges), menus, and complex custom dialog windows via code.
    • Integration: The library can be embedded into other programs.

    Script Editor App

    • C# Scripting: Uses C# as the scripting language, featuring an editor with Intellisense, a script manager, a cookbook, and a debugger.
    • Recording Tools: Tools for recording keyboard/mouse input and selecting UI objects (buttons, links, images).
    • Extensibility: Supports .NET and other libraries, including NuGet, Windows API, and icon sets.
    • Output: Capability to create independent .exe programs and .NET libraries.
  3. Understand the LibreAutomate application structure

    master
    LibreAutomate is an integrated scripting environment for creating and executing automation scripts using C#. The main window consists of a code editor, several functional panels, toolbars, and a menu bar. A tray icon is also available to show/activate the editor window or access a context menu. The application can be configured to hide the main window based on settings.
  4. top-level statements

    master

    syntax, which allows for concise code. A script can contain the following components in this specific order (all are optional):

    1. Comments or documentation comments: e.g., /// File description.
    2. Properties: Defined via /*/ properties /*/. These can be managed through the Properties dialog.
    3. using directives: Note that these do not need to be specified in the global.cs file.
    4. script.setup() or runtime property setup: Code used to configure the script's environment.
    5. Script code: The main logic, which can include local functions.
    6. Classes and other types: Definitions for custom types used within the script.

    If you prefer the traditional C# structure, you can use a class with a Main function by selecting Code > Simple > Add function Main from the menu.

    /// <summary>
    /// My script description
    /// </summary>
    
    /*/ properties /*/
    
    using System;
    
    // Script code using top-level statements
    Console.WriteLine("Hello from LibreAutomate!");
    
    // Custom types
    public class MyHelper { }
  5. How NuGet package installation and storage works

    master

    LibreAutomate manages NuGet packages using a two-tier storage system:

    1. Global Cache: Packages are first downloaded to the shared cache at folders.Profile + ".nuget\packages". This folder is safe to delete.
    2. Workspace Folder: LibreAutomate copies the required files from the cache to workspace\.nuget\<folder_specified_in_combo_box>. This is the folder used by the editor and scripts.

    Key Behaviors:

    • Isolation: You can install different versions of the same package into different folders (e.g., FolderA for version 1 and FolderB for version 2) to avoid conflicts.
    • Dependencies: When you install a top-level package, its dependencies are also installed. While the tool only shows the top-level package, all dependencies are available for use in your scripts.
    • exeProgram Scripts: When compiling a script with the exeProgram role, runtime files are copied to the output folder.
  6. Configure PiP session settings and limitations

    master

    PiP sessions run under the same Windows user account as your main session, meaning they share user files and settings. However, certain LibreAutomate settings are isolated per session:

    Separate settings (per session):

    • App settings: Start hidden, Visible if, Check for updates.
    • Workspace settings: Startup scripts, Auto-backup.
    • User Interface: Hotkeys (all pages), Window positions (main and tool windows), Bookmarks, Breakpoints, Expanded folders, Open files, and Folding.

    Shared/Managed behavior:

    • You can manage and edit the same workspace files (scripts, etc.) in both sessions simultaneously.
    • You can run any script in either the PiP or main session.
    • Note: The App > Start with Windows setting is ignored in PiP sessions because PiP sessions always start with the application.
  7. Define snippet fields and variables

    master

    Snippet code supports specific fields (for tab-stops) and variables (for dynamic content).

    Fields (Tab-stops)

    Used to navigate through the snippet during insertion using the Tab key:

    • $0: The final text cursor position after pressing Enter or multiple Tab presses.
    • ${n:text}: A field with tab-stop index n and default text. Example: ${1:i}.
    • $n or ${n}: A reference to an existing ${n:text} field. Updating one updates all matching instances.

    Variables

    • ${SELECTED_TEXT}: The currently selected text (used only with the Surround feature).
    • ${RANDOM}: A random decimal number.
    • ${RANDOM_HEX}: A random hexadecimal number.
    • ${GUID}: A new GUID.
    • ${VAR}: A local variable of the type specified in the snippet's \${VAR} property.

    Escape Sequences

    Use \$, \\, or \} to escape these characters.

    Note: Other VSCode snippet variables and features are not supported.

    for (int ${1:i} = 0; $1 < ${2:count}; $1++) {
    	${SELECTED_TEXT}$0
    }
  8. Enable Auto backup via Git

    master

    Enabling Auto backup (Git commit) will silently run a Git commit when the LibreAutomate window is first made visible after loading a workspace, or after several hours have passed since the last backup. This creates a local backup of workspace files (like scripts).

    To manually manage or upload these backups, use the menu File > Git.

  9. Manage files and workspaces in LibreAutomate

    master

    A workspace is a folder on disk that contains the following structure:

    • files/: Contains the workspace's files and folders.
    • files.xml: The list of files and folders in the workspace.
    • settings.json: Workspace-specific settings.
    • bookmarks.csv: Saved bookmarks.
    • .state/: Stores code editor states (folding, markers, current position).
    • exe/ and dll/: Default output folders for files compiled with roles exeProgram or classLibrary.

    File Types

    • Script: C# code files that can be executed directly like a program.
    • Class: C# code files containing classes/functions used by other files.
    • Text files: .txt, .xml, etc., editable in the code editor.
    • Other files: Non-editable files (e.g., images) that can be added to exe program resources.

    Folder Types

    • Simple folders: Standard directories.
    • Project folders: Folders named with the @ prefix (e.g., @Name).
  10. Reference vector icons by name string

    master

    In scripts, vector icons are referenced using a specific string format: "*Pack.Name color".

    • Pack Name: The name of the icon pack.
    • Icon Name: The specific name of the icon.
    • Color: Optional; defaults to black if not specified.
    • Advanced Parameters: You can optionally include size, margins, or multiple icons (layers) within the string. Detailed syntax is available via ImageUtil.LoadWpfImageElement.

    In the Icons tool, you can click the Name button in the Menu/toolbar/etc icon section to copy the correctly formatted string to your clipboard.

    // Example of the icon name string format
    string myIcon = "*MahApps.Metro.IconPacks.Color Red";
  11. Understand changes to program execution and apphost in v1.16.2+

    master

    Starting with version 1.16.2, all LibreAutomate (LA) and LA-generated programs use the standard .NET apphost (.exe) and .json configuration files, matching the behavior of Visual Studio-created programs. This change was implemented to reduce antivirus false positives.

    Key behaviors:

    • Portable LA Runtime: Programs using the exeProgram role that are compiled or executed within portable LA will use the portable LA .NET runtime, provided they remain on the same drive and are not moved. This allows them to run on computers without a shared .NET runtime installed.
    • UAC Constraints: Portable LA cannot launch an exeProgram task with a different UAC integrity level (via the uac property) if the program is located on a different drive than the portable LA installation, unless a shared .NET runtime is present on the host machine.