Yes, you can absolutely automate this workflow, but because ONLYOFFICE Desktop
Editors render their documents inside a custom web-based rendering canvas
(similar to Chromium/Electron), Dogtail won't be able to read the data inside
the spreadsheet cells via AT-SPI. [1, 2]
However, Dogtail can control the application window, menus, and top-level
navigation, while standard Linux CLI tools can handle mailbox polling, file
processing, and capturing screenshots.
To accomplish this for asynchronous auditing, you can build a hybrid
architecture combining Python's IMAP tools, Dogtail, and import (ImageMagick)
or scrot.
------------------------------
## The Audit Pipeline Architecture
[Mailbox Queue] (Python IMAP Polling) [Save .xlsx File]
(Dogtail App Launcher) [Open in ONLYOFFICE on Display :99]
(System/Dogtail Capture) [Take Screenshot] [Archived Audit Trail]
## Component Setup## 1. Install System Prerequisites
Make sure you have ONLYOFFICE and an image utility installed on your Debian 12
machine: [3]
# Install ONLYOFFICE via official repository or .deb
sudo apt-get install onlyoffice-desktopeditors -y
# Install scrot for taking clean display screenshots
sudo apt install -y scrot
## 2. The Complete Automation Script (audit_pipeline.py)
This standalone Python script orchestrates checking a mailbox queue, saving an
attachment, utilizing Dogtail to launch ONLYOFFICE inside your Xvfb :99
window, waiting for it to render, taking a screenshot, and closing it cleanly.
[1]
#!/usr/bin/env python3import osimport timeimport subprocessimport
imaplibimport emailfrom dogtail.tree import root
# 1. Pipeline Environment Configuration
os.environ["DISPLAY"] = ":99"
os.environ["DBUS_SESSION_BUS_ADDRESS"] = f"unix:path=/run/user/{os.getuid()}/bu
s"
os.environ["GTK_MODULES"] = "gail:atk-bridge"
AUDIT_DIR = "/home/x/audit_trail"
os.makedirs(AUDIT_DIR, exist_ok=True)
def fetch_incoming_xlsx():
"""
Mock function representing your asynchronous mailbox queue.
Replace this with real imaplib logic to drain your incoming queue.
"""
# For testing purposes, assume an XLS file was written to disk by your
queue
sample_file = "/home/x/received_invoice.xlsx"
return sample_file if os.path.exists(sample_file) else None
def main():
xlsx_file = fetch_incoming_xlsx()
if not xlsx_file:
print("No incoming files found in the mailbox queue.")
return
print(f"Processing incoming audit for: {xlsx_file}")
timestamp = time.strftime("%Y%m%d-%H%M%S")
screenshot_path = os.path.join(AUDIT_DIR, f"audit_{timestamp}.png")
# 2. Use subprocess to launch ONLYOFFICE with the target file
# This automatically spawns the app directly into your Xvfb session
process = subprocess.Popen(['desktopeditors', xlsx_file])
# Allow the spreadsheet engine ample time to fully load and recalculate
formulas
print("Waiting for ONLYOFFICE engine to paint...")
time.sleep(8)
# 3. Take a screenshot of Display :99 via scrot
print(f"Capturing visual audit log to {screenshot_path}")
subprocess.run(['scrot', '-d', '1', screenshot_path])
# 4. Use Dogtail to cleanly close ONLYOFFICE via the window container
print("Closing ONLYOFFICE...")
try:
# Dogtail finds the top level window container via AT-SPI
onlyoffice_app = root.application('desktopeditors')
# Look for the global close action or window controller
# If the app blocks on a 'Save changes?' prompt, handle it here:
if onlyoffice_app.childs():
process.terminate()
except Exception:
# Fallback hard kill if window interface becomes unresponsive
process.kill()
print("[SUCCESS] Audit cycle complete.")
if __name__ == "__main__":
main()
## Strategic Alternatives to Keep in Mind
If your audit logic requires reading actual cell text or formulas
programmatically rather than just capturing a visual screenshot:
*
* Alternative 1 (No GUI Needed): Use a native Python library like openpyxl or
pandas. It can parse incoming Excel files in memory without needing a GUI
server, which is significantly faster and lower-overhead for auditing numbers
or text data.
* Alternative 2 (Official API Integration): Look into the [ONLYOFFICE
Automation API](https://api.onlyoffice.com/docs/docs-api/samples/automation-api
/), which allows you to extract document contents or manipulate cells via
external bindings if you pivot to using their Document Server framework. [4,
5, 6]
*
Would you like help mapping out the IMAP mail downloading code to tie directly
into this file processing loop, or do you need a trick to handle ONLYOFFICE's
"Save Changes?" popups if users modify files before sending them?
[1] [https://cua.ai](https://cua.ai/blog/inside-linux-computer-use)
[2] [https://www.onlyoffice.com](https://www.onlyoffice.com/blog/2023/10/screen
-readers-in-onlyoffice)
[3] [https://helpcenter.onlyoffice.com](https://helpcenter.onlyoffice.com/deskt
op/installation/desktop-install-ubuntu.aspx)
[4] [https://www.onlyoffice.com](https://www.onlyoffice.com/automation-api)
[5] [https://api.onlyoffice.com](https://api.onlyoffice.com/docs/docs-api/sampl
es/automation-api/)
[6] [https://github.com](https://github.com/ONLYOFFICE/document-server-integrat
ion)