python - 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>')
解决方案
推荐阅读
- database - 如何使只读从属 Postgresql12 数据库可写?
- java - 如何防止Java自动舍入
- google-cloud-firestore - 使用 Firestore 数据库时,在 Play Store 上发布的应用的最佳规则是什么?
- java - java如何计算数组中的重复元素
- user-interface - 如何在 Flutter for mobile 上创建可转换的网格 UI?
- google-places-api - Google Places API _id 和 place_id 之间的区别
- c# - 转换通用类型 - 为什么使用括号“()”进行直接转换会产生编译错误,但使用“as”关键字进行转换?
- spring - Spring Boot:forward-headers-strategy 没有效果
- python - 如何保存和加载谷歌 NLP 改革者模型
- python - 使用 Python/Tkinter 文本函数通过鼠标拖动选择列