如何通过脚本启动Multilogin X的agent
使用 Python 脚本在 Windows、macOS 或 Linux 上启动 Multilogin 桌面应用,然后再运行其他本地自动化。
➡️ 选择适用于您操作系统的脚本 → 如有需要,更新应用路径 → 从 IDE 或终端运行脚本。
如果您的自动化工作流程需要先运行 Multilogin 桌面应用及其内置启动器,请使用此方法。
Agent需要显示器才能工作。如果您的系统没有显示器,请使用虚拟显示器。示例(适用于Linux ):
xvfb-run mlx
开始之前
请确保:
- 已安装 Multilogin 桌面应用
- 已安装 Python
- 您知道如何从 IDE 或终端运行 Python 脚本
- 在 Linux 上,可以使用图形显示环境,或已配置受支持的虚拟显示环境
Windows
通过IDE或命令提示符运行脚本。不知道怎么做?请阅读以下文章: 自动化脚本入门。
import os
import subprocess
def connect_agent():
username = os.getlogin()
exe_path = f'C:\\Users\\AntonLa\\AppData\\Local\\Multilogin\\agent.exe'
agent_connection = subprocess.run([exe_path])
assert agent_connection.returncode == 0
if agent_connection.returncode == 0:
print("Agent connected")
else:
print(f"Failed to connect agent. Error {agent_connection.returncode}")
if __name__ == "__main__":
connect_agent()
macOS
通过IDE或终端运行脚本。不知道怎么操作?请阅读这篇文章: 自动化脚本入门。
import subprocess
def connect_agent():
agent_connection = subprocess.Popen(['open', '/Applications/Multilogin.app/'])
agent_connection.wait()
return_code = agent_connection.returncode
if return_code == 0:
print("Agent connected")
else:
print(f"Failed to connect agent. Error {return_code}")
connect_agent()
Linux
通过IDE或终端运行脚本。不知道怎么操作?请阅读这篇文章: 自动化脚本入门。
import os
import subprocess
def connect_agent():
username = os.getlogin()
exe_path = f'/opt/mlx/agent.bin'
agent_connection = subprocess.run([exe_path])
assert agent_connection.returncode == 0
if agent_connection.returncode == 0:
print("Agent connected")
else:
print(f"Failed to connect agent. Error {agent_connection.returncode}")
if __name__ == "__main__":
connect_agent()