首页 > 解决方案 > Python 无法自动启动没有 $DISPLAY 的 dbus-daemon for X11 with autokey

问题描述

嗨 :) 我在树莓派操作系统上使用自动键。

我只想将自动键脚本(autokey-run -s autokeyscript)与 crontab 一起使用(重新启动时)

但是,有一些错误。

我已经试过了export DISPLAY=:0。但是会出现相同的错误日志。

crontab 日志

  File "/usr/bin/autokey-run", line 34, in <module>
    bus = dbus.SessionBus()
  File "/usr/lib/python2.7/dist-packages/dbus/_dbus.py", line 211, in __new__
    mainloop=mainloop)
  File "/usr/lib/python2.7/dist-packages/dbus/_dbus.py", line 100, in __new__
    bus = BusConnection.__new__(subclass, bus_type, mainloop=mainloop)
  File "/usr/lib/python2.7/dist-packages/dbus/bus.py", line 122, in __new__
    bus = cls._new_for_bus(address_or_type, mainloop=mainloop)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
display started

自动键脚本

import time

image_path = '/dir/'
image_name = 'python file'
   
time.sleep(5)

# Open Terminal and run python script
# I know that I can run python script without autokey with using crontab, but I have to do this with this method.
keyboard.send_keys('<ctrl>+<alt>+t')
keyboard.send_keys(image_path)


keyboard.send_keys('<enter>')
time.sleep(3)

#keyboard.send_keys('<ctrl>+f')
keyboard.send_keys(image_name)
keyboard.send_keys('<enter>')
time.sleep(3)
keyboard.send_keys('<enter>')

标签: pythonlinuxraspberry-pidbusautokey

解决方案


推荐阅读