python - 使用 Appkit 和 Python 在 OSX 上隐藏鼠标光标

标签 python macos appkit pyobjc

我正在尝试在 OSX 10.9 上编写隐藏鼠标光标的脚本。我让 Chrome 启动并全屏显示一个自助服务终端,我想定期运行一个脚本来隐藏光标。

Applescript 不再直接支持“调用方法”来调用 objective-c 方法,所以我认为最简单的方法是使用提供的 python 中的 AppKit。

它崩溃了:

$ python
Python 2.7.5 (default, Mar  9 2014, 22:15:05) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import AppKit
>>> AppKit.NSCursor.hide()
Assertion failed: (CGAtomicGet(&is_initialized)), function CGSConnectionByID, file Services/Connection/CGSConnection.c, line 123.
Abort trap: 6

我怀疑我需要进行一个先决条件调用来初始化某物,但我在通过 docs/google 进行挖掘时还没有发现任何东西。

我错过了什么?

最佳答案

我很幸运地使用了 PyObjC 附带的 Quartz :

import Quartz
Quartz.CGDisplayHideCursor(Quartz.CGMainDisplayID())

关于python - 使用 Appkit 和 Python 在 OSX 上隐藏鼠标光标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25330827/

相关文章:

macos - 如何在没有子类化的情况下绘制 cocoa 聚焦环?

macos - 基于 View 和单元格的 NSTableView

swift - 如何让 Swift Coordinator 反射(reflect) parent 的绑定(bind)变化?

python - 将保存的 keras 模型从 gs 加载到 pydatalab

python - App Engine httplib.HTTPConnection 截止日期

python - GTK - Python Treeview 排序列数据(文件大小 - 字节数据)

python - 多索引数据帧的每一行的减法表(差异)

objective-c - 获取垃圾桶的全尺寸图标

swift - 如何从一个 child 扩展到它的第一个 parent ?

swift/ cocoa : launchApplication(at:options:configuration:) and catching errors