Prompt
How do I automate tasks in legacy desktop apps without APIs?
Latest observation
If a legacy desktop app has no API, you usually automate it through the user interface or by observing/controlling the process indirectly. The best approach depends on how much access you have and how stable the app is.
Common automation approaches
1) UI scripting / UI automation
Use accessibility layers or UI automation frameworks to click buttons, fill fields, read text, and navigate windows.
Tools/examples:
- Windows: Power Automate Desktop, AutoHotkey, Pywinauto, WinAppDriver, UIAutomation
- macOS: AppleScript, Shortcuts, UI scripting with Accessibility
- Linux: xdotool, AT-SPI tools, Dogtail, PyAutoGUI
Best for: apps with standard controls and accessible UI elements.
2) Keyboard/mouse macro automation
Send keystrokes, mouse clicks, and hotkeys as if a human were using the app.
Tools/examples:
- AutoHotkey
- PyAutoGUI
- SikuliX (image-based automation)
Best for: very old apps, Citrix/VDI sessions, custom-rendered UIs.
Downside: brittle if window positions, resolution, or timing change.
3) Image-based automation
Recognize buttons/text using screenshots and computer vision, then click based on what’s visible.
Tools/examples:
- SikuliX
- OpenCV + PyAutoGUI
- Robocorp / RPA frameworks with image matching
Best for: apps that don’t expose UI elements to automation tools.
4) File-based automation
Instead of controlling the UI, automate by reading/writing the files the app uses.
Examples:
- Import/export CSV, XML, INI, JSON, DB files
- Update configuration files
- Drop files into watched folders
Best for: workflows where the app can be driven by files rather than clicks.
5) Database or backend-level integration
If the app stores data in a local/shared database, automate directly against the database or backend tables.
Best for: systems where you’re allowed to access the data layer.
Caution: must understand data integrity, locks, and business rules.
6) Hooking/intercepting process behavior
Advanced techniques can inspect window messages, API calls, or memory, or inject code into the process.
Best for: specialized internal tooling or reverse engineering.
Caution: more fragile, may violate licensing or security policies, and can be risky.
Practical recommendation
Start with this order:
-
Check for hidden APIs or integration points
- COM interfaces
- command-line options
- config files
- export/import features
- database access
-
Try UI automation
- Prefer accessibility/UIA over raw mouse automation
-
Fallback to image/coordinate automation
- Use only when the UI is inaccessible
-
Use file/database automation if possible
- Usually more reliable than UI driving
Good practices
- Make workflows idempotent when possible
- Add logging and screenshots for failures
- Use waits/retries instead of fixed sleep times
- Validate each step before continuing
- Run in a dedicated environment with fixed resolution, scaling, and theme
- Prefer selectors/element names over screen coordinates
Example options by platform
Windows
- Power Automate Desktop for low-code automation
- AutoHotkey for scripts and hotkeys
- Pywinauto for native Windows UI automation
- SikuliX for image-based tasks
macOS
- AppleScript for scriptable apps
- Shortcuts for simple flows
- Accessibility UI scripting for GUI control
Linux
- xdotool for keyboard/mouse events
- PyAutoGUI for cross-platform scripting
- AT-SPI/Dogtail for accessible apps
When to avoid UI automation
Avoid it if:
- The app changes often
- The UI is highly dynamic or canvas-based
- Reliability is critical and there’s a better data-layer option
- You need high throughput or concurrency
In those cases, consider wrapping the app with a custom integration, using database/file access, or replacing the app entirely.
If you want, I can suggest the best automation tool for your OS and app type if you tell me:
- your OS,
- the app type,
- and what task you want to automate.