[编辑:对于您的 ExtendScript 问题基本上给出了 AppleScript 答案,我深表歉意。我只是在查看 AS 问题,忘记了我去了不同的部分。我只能希望你在 Mac 上。如果没有,我想我会吃掉我的反对票并哭泣。]
有一个解决方法。它的优点(以及它的部分变通方法)是它适用于所有应用程序。缺点是它需要python(无论如何都应该在你的Mac上——如果没有的话,安装起来相当容易),以及两个第三方软件(都是免费的),“checkModifierKeys”和“cliclick”。多年来,我一直在使用出现在我的脚本菜单中的脚本。
python部分在这里描述:http://thechrisgreen.blogspot.com/2013/04/python-script-for-getting-pixel-color.html
可以使用 AS do shell script 命令保存、执行和调用此脚本。
其余的,用于选择屏幕上的一个点并等待按下控制键(这就是我的工作方式)非常简单。
基本的 checkModifierKeys 部分(一直等到按下 Control 键)是:
set controlIsDown to false
repeat until (controlIsDown)
set initialCheck to ((do shell script "/usr/local/bin/checkModifierKeys control"))
if initialCheck = "1" then set controlIsDown to true
end repeat
cliclick 部分(获取坐标)是:
set xyGrabbed to do shell script "/usr/local/bin/cliclick p"
这似乎还有很长的路要走,但效果很好。我的版本使用此处理程序将 rgb 值转换为十六进制,这对我的目的很有用:
to makeHex(theNumber) --was anInteger
--Converts an unsigned integer to a two-digit hexadecimal value
set theResult to ""
repeat with theIndex from 1 to 0 by -1
set theBase to (16 ^ theIndex) as integer
if theNumber is greater than or equal to theBase then
set theMultiplier to ((theNumber - (theNumber mod theBase)) / theBase) as integer
set theResult to theResult & item theMultiplier of ¬
{1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"}
set theNumber to (theNumber - theBase * theMultiplier)
else
set theResult to (theResult & "0")
end if
end repeat
theResult
end makeHex