### Install and Use Humanizer NuGet Package Source: https://github.com/qgindi/la-doc4ai/blob/main/cookbook/[cookbook] dot-NET, NuGet, other libraries.md This example shows how to install a NuGet package, specifically 'Humanizer', and use its functionality. The `/*/ nuget -[PackageName]; /*/` directive is used for installation, followed by the necessary `using` statement and code. ```csharp /*/ nuget -\Humanizer; /*/ using Humanizer; var s = "one two"; s = s.Titleize(); print.it(s); ``` -------------------------------- ### C# Script: Setup and Main Code Source: https://github.com/qgindi/la-doc4ai/blob/main/editor/[editor] Scripts.md Provides an example of setting run-time properties using 'Au.script.setup' and includes the main script code. This section defines the core logic that will be executed when the script is run. ```csharp // Au.script.setup( // role: "miniProgram", // default // timeout: 0, // infinity // log: "script.log" // ); Console.WriteLine("Hello from script!"); ``` -------------------------------- ### Example: Starting a GroupBox with a Grid (C#) Source: https://github.com/qgindi/la-doc4ai/blob/main/api/Au/wpfBuilder/[api] Au.wpfBuilder.StartGrid.md Demonstrates the usage of the StartGrid overload that creates a GroupBox with an internal Grid panel and a specified header. ```csharp b.StartGrid("Group"); ``` -------------------------------- ### HTTP Server Setup and Basic Request Handling Source: https://github.com/qgindi/la-doc4ai/blob/main/cookbook/[cookbook] Run script on another computer; HTTP server.md This C# code snippet demonstrates how to set up an HTTP server using `HttpServerSession.Listen` and handle incoming HTTP requests. It includes basic authentication and shows how to process simple GET requests, print request details, and send a text response. The `client_example_simple` function shows corresponding client-side HTTP GET requests. ```csharp HttpServerSession.Listen(); class HttpServerSessionExamples : HttpServerSession { protected override void MessageReceived(HSMessage m, HSResponse r) { Auth((u, p) => p == "password278351"); print.it(m.Method, m.TargetPath, m.UrlParameters, m.Text, m.Headers); r.SetContentText("text"); } } static void client_example_simple() { internet.http.Get("http://SERVER:4455"); internet.http.Get("http://SERVER:4455", auth: ":password278351"); internet.http.Get("http://[::1]:4455"); string r = internet.http.Get("http://SERVER:4455").Text(); print.it(r); } ``` -------------------------------- ### Example: Starting an Expander with a Grid and Container Access (C#) Source: https://github.com/qgindi/la-doc4ai/blob/main/api/Au/wpfBuilder/[api] Au.wpfBuilder.StartGrid.md Illustrates how to use the StartGrid overload that provides access to the created container (Expander in this case) and allows modifying its properties after creation. ```csharp b.StartGrid(out Expander g, "Expander"); g.IsExpanded=true; ``` -------------------------------- ### Example Usage: Download File with Progress - C# Source: https://github.com/qgindi/la-doc4ai/blob/main/api/Au.Types/ExtInternet/[api] Au.Types.ExtInternet.DownloadAsync.md An example demonstrating how to use the DownloadAsync method to download a file from a URL. This snippet shows a common pattern where an HTTP GET request is made, and if successful, the content is downloaded to a file named 'zip'. The example highlights the check for successful download before proceeding. ```csharp if (!internet.http.Get(url, true).Download(zip)) return; ``` -------------------------------- ### Call Functions and Create Objects - General Scripting Source: https://github.com/qgindi/la-doc4ai/blob/main/cookbook/[cookbook] Functions (methods, properties).md Demonstrates calling different types of functions like methods, properties, and constructors. It shows how to interact with objects and variables, and includes examples of property gets and sets. ```General Scripting dialog.showInfo("example"); //call function (method) showInfo which is defined in type dialog. Pass 1 argument. var w = wnd.find(1, "*- Notepad"); //call function (method) find which is defined in type wnd. Pass 2 arguments and assign its return value to variable w. w.Activate(); //call function (method) Activate which is defined in type wnd var s = w.Name; //call function (property-get) Name which is defined in type wnd. Assign the return value to variable s. var b = new StringBuilder(1000); //create new object of type StringBuilder and call its constructor function with 1 argument. Assign the object to variable b. b.Capacity = 10000; //call function (property-set) Capacity which is defined in type StringBuilder. Pass a value. int x = 5; //this statement does not call functions ``` -------------------------------- ### Basic RXMatch Example Source: https://github.com/qgindi/la-doc4ai/blob/main/api/Au.Types/RXMatch/[api] Au.Types.RXMatch.md Demonstrates how to use the RxMatch extension method to find a pattern in a string and access the whole match and captured groups. The example shows retrieving the start index, value, and group details of the match. ```csharp var s = "ab cd-45-ef gh"; if(s.RxMatch(@"\b([a-z]+)-(\d+)\b", out RXMatch m)) print.it( m.GroupCountPlusOne, //3 (whole match and 2 groups) m.Start, //3, same as m[0].Index m.Value, //"cd-45-ef", same as m[0].Value m[1].Start, //3 m[1].Value, //"cd" m[2].Start, //6 m[2].Value //"45" ); ``` -------------------------------- ### Internet Communication Example - C# Source: https://github.com/qgindi/la-doc4ai/blob/main/cookbook/[cookbook] Run script on another computer; HTTP server.md Provides an example of client-side internet communication, specifically an HTTP GET request to a server accessible via a public URL (potentially through ngrok). It includes an authorization token in the request. ```csharp internet.http.Get("https://1111-11-111-11-111.ngrok-free.app/", auth: ":password278351"); ``` -------------------------------- ### Start Thread with Basic Configuration (C#) Source: https://github.com/qgindi/la-doc4ai/blob/main/api/Au/run/[api] Au.run.thread.md This overload starts a new thread with specified configuration. It creates a new Thread object, sets its background and apartment state properties, and then starts the thread execution. The thread procedure is provided as an Action delegate. It returns the created Thread object. ```csharp public static Thread thread(Action threadProc, bool background = true, bool sta = true) ``` -------------------------------- ### Launching Au.Editor.exe with Options Source: https://github.com/qgindi/la-doc4ai/blob/main/editor/[editor] Command line.md These examples show how to launch `Au.Editor.exe` with specific command-line flags to control its behavior, such as showing the main window or starting it without administrator privileges. ```bash Au.Editor.exe /v Au.Editor.exe /n ``` -------------------------------- ### Example Usage: Downloading a File - C# Source: https://github.com/qgindi/la-doc4ai/blob/main/api/Au.Types/ExtInternet/[api] Au.Types.ExtInternet.Download.md A practical example demonstrating how to use the Download method to fetch a file from a URL and save it to a local path. This snippet illustrates a common use case for downloading resources from the internet. ```csharp if (!internet.http.Get(url, true).Download(zip)) return; ``` -------------------------------- ### Toolbar Button Addition Examples (C#) Source: https://github.com/qgindi/la-doc4ai/blob/main/api/Au/toolbar/[api] Au.toolbar.Item.md Provides examples of how to add buttons to the toolbar using the `Au.toolbar.Add` method and the indexer syntax. It demonstrates basic addition and how to set tooltips for the added buttons. ```csharp tb.Add("Example", o => print.it(o)); tb["Example"] = o => print.it(o); ``` ```csharp var b = tb.Add("Example", o => print.it(o)); b.Tooltip="tt"; tb.Add("Example", o => print.it(o)).Tooltip="tt"; tb["Example"] = o => print.it(o); var b=tb.Last; b.Tooltip="tt"; tb["Example"] = o => print.it(o); tb.Last.Tooltip="tt"; ``` -------------------------------- ### C# Program Class with Main Function Example Source: https://github.com/qgindi/la-doc4ai/blob/main/cookbook/[cookbook] Script class with Main().md Demonstrates the classic C# syntax using a `Program` class with a `Main` method. This approach allows for class-level fields, methods, and modifiers, overcoming some limitations of C# top-level statements. The code initializes script setup, prints a message, and defines class members. ```csharp class Program { static void Main(string[] a) => new Program(a); Program(string[] args) { script.setup(trayIcon: true, sleepExit: true); print.it("script code"); _field1 = 1; Function1(); } int _field1; //this is a field, not a local variable void Function1() { } //this is a class function, not a local function } ``` -------------------------------- ### Download Web Page Content Source: https://github.com/qgindi/la-doc4ai/blob/main/cookbook/[cookbook] Http get web page, download file.md Fetches the HTML content of a given URL. It uses the `internet.http.Get` method to retrieve the page and `.Text()` to get the content as a string. No specific dependencies are required beyond the `System.Net.Http` namespace. ```csharp using System.Net.Http; string html = internet.http.Get("https://www.example.com").Text(); print.it(html); ``` -------------------------------- ### Example Usage of Window Property Management Source: https://github.com/qgindi/la-doc4ai/blob/main/api/Au/wnd/[api] Au.wnd.Prop.md This example demonstrates how to find a window, set a custom property 'example' to the value 5, print the property's value, print all properties, and then remove the property. It highlights the importance of removing properties to avoid potential application instability. ```csharp var w = wnd.find("* Explorer"); w.Prop.Set("example", 5); print.it(w.Prop["example"]); print.it(w.Prop); //all w properties w.Prop.Remove("example"); //you should always remove window properties if don't want to see unrelated applications crashing after some time. And don't use many unique property names. ``` -------------------------------- ### Example: Find Notepad Window (C#) Source: https://github.com/qgindi/la-doc4ai/blob/main/api/Au/wnd/[api] Au.wnd.find.md Demonstrates how to use the Au.wnd.find method to locate a Notepad window. It includes checks for whether the window was found and provides an example of how to handle a missing window. ```csharp wnd w = wnd.find("* Notepad"); if(w.Is0) { print.it("not found"); return; } ``` -------------------------------- ### Extract Substrings from Strings Source: https://github.com/qgindi/la-doc4ai/blob/main/cookbook/[cookbook] Simple string functions.md Covers various methods for extracting parts of a string, including `Substring()` with start index and length, `Substring()` with only start index, `Remove()` to get the beginning, and index-based slicing like `[start..end]`, `[start..]`, `[..end]`, `[^n..]`, and `[start..^end]`. ```C# string s = "Text example"; var middle = s.Substring(5, 4); //get 4 characters starting from index 5 var end = s.Substring(5); //get from index 5 until the end var start = s.Remove(4); //get 4 characters at the start print.it(middle, end, start); middle = s[5..9]; //get from index 5 to 9 (not including s[9]) end = s[5..]; //get from index 5 until the end start = s[..4]; //get 4 characters at the start var end2 = s[^3..]; //get 3 characters at the end var middle2 = s[2..^2]; //get all except 2 characters at the start and end print.it(middle, end, start, end2, middle2); ``` -------------------------------- ### Example: Get UI Element at Specific Coordinates Source: https://github.com/qgindi/la-doc4ai/blob/main/api/Au/elm/[api] Au.elm.fromXY.md Demonstrates how to get a UI element at the screen coordinates (100, 200) using the Au.elm.fromXY method and print the result. ```C# var e = elm.fromXY((100, 200)); print.it(e); ``` -------------------------------- ### Quick Macros Script Example Source: https://github.com/qgindi/la-doc4ai/blob/main/editor/[editor] Compared with QM.md Demonstrates a basic script in Quick Macros (QM) for window interaction, key input, and a simple loop. ```qm int w=win("- Mozilla Firefox") act w ;;comment lef 331 115 w 2 key L "text" Y int i for i 0 5 out i out i*i ``` -------------------------------- ### C# Creating and Configuring a Keys Instance Source: https://github.com/qgindi/la-doc4ai/blob/main/api/Au/opt/[api] Au.opt.key.md Illustrates creating a new `keys` instance, copying options from `opt.key`, modifying the new instance's options without affecting the original, and sending key commands. ```csharp var k = new keys(opt.key); //create new keys instance and copy options from opt.key to it k.Options.KeySpeed = 100; //changes option of k but not of opt.key k.Add("Right*10 Ctrl+A").SendNow(); //uses options of k ``` -------------------------------- ### C# Example Class for JSON Serialization Source: https://github.com/qgindi/la-doc4ai/blob/main/cookbook/[cookbook] JSON.md Defines an example C# class named 'Example' intended for JSON serialization and deserialization. It includes properties, fields, and attributes like JsonIgnore to control how the object is represented in JSON format. Note the use of a record class for conciseness. ```csharp using System.Text.Json.Serialization; record class Example { public int Property { get; set; } public string field = "text"; public POINT p; public string[] a; [JsonIgnore] public int excludedExplicitly = 1; int _excludedBecausePrivate = 2; } // Assuming POINT is a defined struct or class, e.g.: // public struct POINT { public int X; public int Y; public POINT(int x, int y) { X = x; Y = y; } } ``` -------------------------------- ### Asynchronous HTTP Download with UI Source: https://github.com/qgindi/la-doc4ai/blob/main/cookbook/[cookbook] Http get web page, download file.md Implements an asynchronous HTTP GET request suitable for UI applications to prevent blocking. It uses `GetAsync` with a `CancellationToken` for timeouts and cancellation, reading the response as a byte array. Includes UI elements for starting and stopping the download. ```csharp var b = new wpfBuilder("Window").Columns(120, 120); CancellationTokenSource cts = null; b.R.AddButton("Download", async o => { o.Button.IsEnabled = false; cts = new CancellationTokenSource(); cts.CancelAfter(10_000); //10 s timeout var ctoken = cts.Token; try { var r4 = await internet.http.GetAsync("http://speedtest.ftp.otenet.gr/files/test10Mb.db", ctoken); r4.EnsureSuccessStatusCode(); var data = await r4.Content.ReadAsByteArrayAsync(ctoken); print.it(data.Length); } catch(OperationCanceledException) { print.it("canceled or timeout"); } catch(Exception e) { print.it(e); } o.Button.IsEnabled = true; cts.Dispose(); cts = null; }); b.AddButton("Stop", _ => { cts?.Cancel(); }); b.Window.Closed += (_, _) => { cts?.Cancel(); }; if (!b.ShowDialog()) return; ``` -------------------------------- ### Au.script.setup Source: https://github.com/qgindi/la-doc4ai/blob/main/api/Au/script/[api] Au.script.setup.md Adds various features to the current script task, such as a tray icon, custom exit conditions, and enhanced debugging capabilities. ```APIDOC ## Au.script.setup ### Description Adds various features to this script task (running script): tray icon, exit on `Ctrl+Alt+Delete`, etc. ### Method `public static void setup(bool trayIcon = false, bool sleepExit = false, bool lockExit = false, bool debug = false, UExcept exception = UExcept.Print, KKey exitKey = 0, KKey pauseKey = KKey.ScrollLock, string f_ = null)` ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```csharp Au.script.setup(trayIcon: true, exitKey: KKey.MediaStop); ``` ### Response #### Success Response (200) N/A #### Response Example N/A ### Remarks - If the program was not compiled in LibreAutomate, calling this function ensures it behaves as if it were (invariant culture, STAThread, unhandled exception action). - Does nothing if the role is `editorExtension` or if running in WPF preview mode. ### Exceptions - `InvalidOperationException`: Thrown if the method has already been called. ``` -------------------------------- ### Get Console Output with Encoding - C# Source: https://github.com/qgindi/la-doc4ai/blob/main/cookbook/[cookbook] Run console program and get its output text.md Captures the complete output text of a console program after it has finished executing. This example specifically shows how to use the 'encoding' parameter to correctly interpret the output, which is crucial if the program's output is not in the default UTF-8 encoding. ```csharp run.console(out var text, @"C:\Test\console3.exe", encoding: Console.OutputEncoding); print.it(text); ``` -------------------------------- ### Example: Restart Explorer Process (C#) Source: https://github.com/qgindi/la-doc4ai/blob/main/api/Au/process/[api] Au.process.terminate.md An example demonstrating how to terminate and then restart the Windows Explorer process. This involves getting the explorer process ID, terminating it with a specific exit code, prompting the user for confirmation, and then relaunching explorer.exe. ```csharp process.terminate(wnd.getwnd.shellWindow.ProcessId, 1); if (!dialog.showYesNo("Restart explorer?")) return; run.it(folders.Windows + @"explorer.exe", flags: RFlags.InheritAdmin); ``` -------------------------------- ### Get and Set Clipboard Text Source: https://github.com/qgindi/la-doc4ai/blob/main/cookbook/[cookbook] Clipboard copy, paste, set-get text etc.md Retrieves the current text from the clipboard and allows setting new text. The example shows getting text, converting it to uppercase, and setting it back if it's not empty. This is useful for text transformations. ```csharp var s2 = clipboard.text; if (!s2.NE()) clipboard.text = s2.Upper(); ``` -------------------------------- ### LibreAutomate C# Script Example Source: https://github.com/qgindi/la-doc4ai/blob/main/editor/[editor] Compared with QM.md Provides the equivalent script in LibreAutomate using C#, showcasing syntax differences for window handling, mouse clicks, key input, and loops. ```csharp var w = wnd.find("*- Mozilla Firefox"); w.Activate(); //comment mouse.click(w, 331, 115); 2.s(); keys.send("Left", "!text", "Enter"); for(int i=0; i<5; i++) { print.it(i); print.it(i*i); } ``` -------------------------------- ### Instantiate and Display osdRect Source: https://github.com/qgindi/la-doc4ai/blob/main/api/Au/osdRect/[api] Au.osdRect.md Demonstrates how to create an instance of the osdRect class, set its properties (rectangle dimensions, color, thickness), show it on screen, and toggle its visibility. This example uses a `using` statement for proper resource management. ```csharp using (var x = new osdRect()) { x.Rect = (300, 300, 100, 100); x.Color = System.Drawing.Color.SlateBlue; x.Thickness = 4; x.Show(); for (int i = 0; i < 5; i++) { 250.ms(); x.Visible = !x.Visible; } } ``` -------------------------------- ### Run Console Program with Arguments - C# Source: https://github.com/qgindi/la-doc4ai/blob/main/cookbook/[cookbook] Run console program and get its output text.md Executes a console program and captures its output. This example demonstrates passing command-line arguments to the program. The function returns an integer representing the program's exit code. ```csharp string v = "example"; int r1 = run.console(@"C:\Test\console1.exe", $ செய்யுங்கள்@"/a \"{v}\" /etc"); ``` -------------------------------- ### PrePostBuild Constructor (C#) Source: https://github.com/qgindi/la-doc4ai/blob/main/api/Au.More/PrePostBuild/[api] Au.More.PrePostBuild.-ctor.md Initializes a new instance of the `PrePostBuild` class. This constructor takes various string and boolean parameters to define the output file, output path, source file path, build role, optimization settings, platform, and whether it's a pre-build or post-build action, and if publishing is enabled. ```csharp public PrePostBuild(string outputFile, string outputPath, string source, string role, bool optimize, string platform, bool preBuild, bool publish) ``` -------------------------------- ### Setup Basic Tray Icon with Au.script.setup Source: https://github.com/qgindi/la-doc4ai/blob/main/cookbook/[cookbook] Tray icon and notifications.md This snippet demonstrates how to enable a standard tray icon using the `Au.script.setup` function. It requires setting the `trayIcon` parameter to true. The `3.s()` likely represents a delay or synchronization mechanism. ```script script.setup(trayIcon: true); 3.s(); ``` -------------------------------- ### Real-time Console Output Handling - C# Source: https://github.com/qgindi/la-doc4ai/blob/main/cookbook/[cookbook] Run console program and get its output text.md Runs a console program and processes its output in real-time using a callback function. This allows immediate handling of output lines as they are generated. An example shows printing each line, and another shows throwing an exception if the output indicates an error. ```csharp run.console(s => print.it(s), @"C:\Test\console2.exe"); //print it run.console(s => { //or do whatever with it if (s.Starts("Error")) throw new Exception(s); }, @"C:\Test\console2.exe"); ``` -------------------------------- ### Access PrePostBuild Info (C#) Source: https://github.com/qgindi/la-doc4ai/blob/main/api/Au.More/PrePostBuild/[api] Au.More.PrePostBuild.md Demonstrates how to access the static Info property of the PrePostBuild class and print its details, including the outputFile. This is typically used within build scripts to get compilation context. ```csharp /*/ role editorExtension; /*/ var c = PrePostBuild.Info; print.it(c); print.it(c.outputFile); ``` -------------------------------- ### Specify Startup Scripts for LibreaAutomate Workspace Source: https://github.com/qgindi/la-doc4ai/blob/main/editor/[editor] Program settings.md Configures a list of scripts to be executed automatically when the program starts or a workspace is loaded. The format is CSV, supporting optional delay specifications in seconds (s) or milliseconds (ms). ```csv Script1.cs \Folder\Script2.cs //Disabled.sc "Script, name, with, commas.cs" Script with delay.cs, 3s Another script with delay.cs, 300ms ``` -------------------------------- ### Example: Copy Image Data (C#) Source: https://github.com/qgindi/la-doc4ai/blob/main/api/Au/clipboard/[api] Au.clipboard.copyData.md Demonstrates how to use the copyData method to retrieve an image from the clipboard. It specifies a lambda expression as the callback to get image data using clipboardData.getImage(). ```csharp var image = clipboard.copyData(() => clipboardData.getImage()); ``` -------------------------------- ### Configure script task features with Au.script.setup Source: https://github.com/qgindi/la-doc4ai/blob/main/api/Au/script/[api] Au.script.setup.md This method configures the behavior of a script task by enabling features such as a tray icon, automatic exit on system sleep or lock, debugging trace listeners, and customizable hotkeys for pausing or exiting the script. It accepts boolean flags and key codes to control these features. ```csharp public static void setup(bool trayIcon = false, bool sleepExit = false, bool lockExit = false, bool debug = false, UExcept exception = UExcept.Print, KKey exitKey = 0, KKey pauseKey = KKey.ScrollLock, string f_ = null) ``` -------------------------------- ### Get System Tick Count (C#) Source: https://github.com/qgindi/la-doc4ai/blob/main/cookbook/[cookbook] Computer time, code speed.md Retrieves the number of milliseconds that have elapsed since the system was started. Note that these functions have a low precision (15-16 ms). ```csharp long t1 = Environment.TickCount64; //with the sleep time long t2 = computer.tickCountWithoutSleep; //without the sleep time ``` -------------------------------- ### C# User-Defined Functions and Method Calls Source: https://github.com/qgindi/la-doc4ai/blob/main/cookbook/[cookbook] CSharp introduction.md This C# example defines and calls a user-defined function named `Example`. The function takes a string and an integer as arguments, converts the string to uppercase, concatenates it with the integer, and prints the result. ```csharp //call function Example 2 times Example("one", 1); Example("two",2); //this is the function void Example(string s, int i) { print.it(s.Upper() + " " + i); } ``` -------------------------------- ### Show Input Dialogs with Various Options (C#) Source: https://github.com/qgindi/la-doc4ai/blob/main/cookbook/[cookbook] Input box dialog.md This snippet showcases the flexibility of the dialog.showInput function in C#. It demonstrates how to capture single-line text, integers, multiline text, passwords, and combo box selections. It also includes an example with a checkbox control. Ensure the Au.dialog library is available. ```csharp if (!dialog.showInput(out string s, "Text input")) return; print.it(s); if (!dialog.showInputNumber(out int i1, "Number input", editText: 0)) return; print.it(i1); if (!dialog.showInput(out string sML, "Multiline text input", editType: DEdit.Multiline)) return; print.it(sML); if (!dialog.showInput(out string pw, "Password input", editType: DEdit.Password)) return; print.it(pw); if (!dialog.showInput(out string s1, "Text input combo", editType: DEdit.Combo, comboItems: "One|Two|Three")) return; print.it(s1); var a = new List(); for (int i = 1; i <= 10; i++) a.Add($"Item {i}"); if (!dialog.showInput(out string s2, "Text input variable combo", editType: DEdit.Combo, comboItems: a)) return; print.it(s2); var c = new DControls() { Checkbox = "Check", IsChecked = true }; if (!dialog.showInput(out string s3, "Text input and checkbox", controls: c)) return; print.it(s3, c.IsChecked); ``` -------------------------------- ### GET - Internet Access Example Source: https://github.com/qgindi/la-doc4ai/blob/main/cookbook/[cookbook] Run script on another computer; HTTP server.md Demonstrates accessing the server remotely using a public URL provided by a service like ngrok. ```APIDOC ## GET ### Description Accesses the server via a public URL, typically through a tunneling service like ngrok. Requires authentication. ### Method GET ### Endpoint `https://..ngrok-free.app/` ### Parameters None ### Request Example ```bash curl -u ":password278351" https://1111-11-111-11-111.ngrok-free.app/ ``` ### Response (Depends on the endpoint being accessed through ngrok, e.g., server's root or other API endpoints) ### Error Handling Network errors, incorrect ngrok URL, or authentication failures can occur. ``` -------------------------------- ### Get Process ID with run.it Source: https://github.com/qgindi/la-doc4ai/blob/main/cookbook/[cookbook] Run program, open document, folder, URL.md The `run.it` function returns a process object from which you can retrieve the `ProcessId` if a new process was started. This is useful for further process management. ```csharp int pid = run.it("notepad.exe").ProcessId; ``` -------------------------------- ### Get COM Object from Word Window - C# Source: https://github.com/qgindi/la-doc4ai/blob/main/api/Au.More/ComUtil/[api] Au.More.ComUtil.GetWindowObject.md Retrieves the COM object for a Microsoft Word window and accesses its document name. This example assumes Word is running and uses the GetWindowObject method with a specific child window class name. ```csharp /*/ com Word 8.7 #6a6b0205.dll; /*/ using Word = Microsoft.Office.Interop.Word; var w = wnd.find(0, null, "OpusApp", "WINWORD.EXE"); Word.Document doc = ((Word.Window)ComUtil.GetWindowObject(w, "_WwG")).Parent; print.it(doc.Name); ``` -------------------------------- ### Get COM Object from Excel Window - C# Source: https://github.com/qgindi/la-doc4ai/blob/main/api/Au.More/ComUtil/[api] Au.More.ComUtil.GetWindowObject.md Retrieves the COM object for a Microsoft Excel window and accesses its workbook name. This example assumes Excel is running and uses the GetWindowObject method with a specific child window class name. ```csharp /*/ com Excel 1.9 #9fdf46bf.dll; /*/ using Excel = Microsoft.Office.Interop.Excel; var w = wnd.find(0, null, "XLMAIN", "EXCEL.EXE"); Excel.Workbook book = ((Excel.Window)ComUtil.GetWindowObject(w, "EXCEL7")).Parent; print.it(book.Name); ``` -------------------------------- ### Activate Window Lightweight (C#) Source: https://github.com/qgindi/la-doc4ai/blob/main/api/Au/wnd/[api] Au.wnd.ActivateL.md The `ActivateL` method provides a non-throwing way to activate a window. The 'full' parameter, when true, calls the more comprehensive `Activate` method and handles potential exceptions by returning false. When false, it performs a basic activation without extensive checks. ```csharp public bool ActivateL(bool full = false) { // Implementation details for activating the window without exceptions. // If full is true, it might call Au.wnd.Activate and catch exceptions. return false; // Placeholder return value } ``` -------------------------------- ### Example: Get UI Element Relative to Work Area Edge Source: https://github.com/qgindi/la-doc4ai/blob/main/api/Au/elm/[api] Au.elm.fromXY.md Shows how to retrieve a UI element positioned 50 pixels from the left and 100 pixels from the bottom edge of the work area, using Coord.Normalize and specifying workArea: true. ```C# var e = elm.fromXY(Coord.Normalize(50, ^100, workArea: true)); print.it(e); ``` -------------------------------- ### Run Notepad and Wait Source: https://github.com/qgindi/la-doc4ai/blob/main/api/Au/run/[api] Au.run.it.md This C# code snippet demonstrates how to run Notepad using `run.it` and then wait for an active Notepad window to appear. It utilizes the `s()` method for waiting and `wnd.wait` to find the window. ```C# run.it("notepad.exe"); 1.s(); wnd w = wnd.wait(10, true, "*- Notepad", "Notepad"); ``` -------------------------------- ### Run and Wait for Window with run.it and wnd.wait Source: https://github.com/qgindi/la-doc4ai/blob/main/cookbook/[cookbook] Run program, open document, folder, URL.md This example demonstrates running Notepad using `run.it` and then waiting for a specific Notepad window to become active using `wnd.wait`. It allows for synchronized interaction with GUI applications. ```csharp run.it("notepad.exe"); wnd w1 = wnd.wait(10, true, "*- Notepad", "Notepad"); print.it(w1); ``` -------------------------------- ### Example: Adding and Retrieving Menu Item (C#) Source: https://github.com/qgindi/la-doc4ai/blob/main/api/Au/popupMenu/[api] Au.popupMenu.Item.md Demonstrates the equivalence between using `Au.popupMenu.Add` and the indexer (`m["text"]=...; var v=m.Last;`) for adding menu items and retrieving the added item. ```csharp var v=m.Add("text", o=>{}); // Using Add method m["text"]=o=>{}; var v=m.Last; // Using indexer ``` -------------------------------- ### Get Links from Browser Window HTML (C#) Source: https://github.com/qgindi/la-doc4ai/blob/main/cookbook/[cookbook] Parse HTML.md This snippet illustrates how to retrieve the HTML content from an active web browser window (specifically Google Chrome in this example) and then parse it using HtmlDocument to find all anchor tags and their associated links. ```csharp var w = wnd.find(1, "*- Google Chrome", "Chrome_WidgetWin_1"); var e = w.Elm["web:DOCUMENT"].Find(30); //w.Elm["web:LINK", "Example"].Find(30); //wait until the web page is loaded and displays an element (link "Example") var html2 = e.Html(true); //print.it(html2); var doc3 = new HtmlDocument(); doc3.LoadHtml(html2); var body = doc3.DocumentNode; foreach (var link in body.Descendants("a")) { print.it(link.InnerText, link.GetAttributeValue("href", null)); } ``` -------------------------------- ### Line and Block Comments Example Source: https://github.com/qgindi/la-doc4ai/blob/main/cookbook/[cookbook] Comments, disabled code.md Demonstrates the use of single-line comments starting with '//' and multi-line block comments enclosed in '/* */'. Also shows how comments can be appended to code lines or used to disable code execution. ```javascript //This is a line comment. print.it(1); //another comment /* This is a block comment. */ print.it(1 /*another comment*/); //print.it("disabled"); //print.it("code"); ``` -------------------------------- ### Trigger Script Execution via Output Link (Python) Source: https://github.com/qgindi/la-doc4ai/blob/main/cookbook/[cookbook] Run script at startup, output link.md This snippet demonstrates how to create a clickable link in the output panel that, when activated, will trigger the execution of a specified script. This is achieved using a special print statement format. ```python print.it("<>Run script