Skip to main content

Exploring Process Automation with Lua: Finding Notepad Processes

A Guide to Loops and Process Identification in Lua Automation IDE

Lua Automation IDE provides a powerful platform for automating tasks and processes. In this guide, we will explore how to use Lua to loop through all running processes and identify those that contain "Notepad" in their names. This can be useful when automating tasks that involve interacting with Notepad processes or monitoring their activity. Let's dive into the code snippet and see how it works.

The code snippet provided demonstrates how to loop through all running processes using the process.GetProcesses() function. Each process is represented by a table, allowing us to access properties such as ProcessName and Id. By using the string.contains() function, we can check if the process name contains the word "Notepad." If it does, we can output the process name and ID using console.WriteLineToBuffer().

-- Loops through all running processes and looks for one that
-- contains notepad.
for index, p in pairs(process.GetProcesses()) do
    if string.contains(p.ProcessName, "Notepad") then
        console.WriteLineToBuffer(p.ProcessName .. ": Process ID = " .. p.Id)
    end
end

console.Flush()

The for loop iterates over each process, assigning the current index to index and the process table to p. Inside the loop, we use an if statement to check if the process name contains "Notepad." If it does, we print the process name and ID to the console buffer using console.WriteLineToBuffer(). Finally, we call console.Flush() to display the output in the console.