【问题标题】:Search color and do something -Apple Script-搜索颜色并做一些事情-Apple Script-
【发布时间】:2021-10-17 04:58:48
【问题描述】:

我以前使用 Windows PC,但现在我有一台 Macbook,所以这是我的问题:

我需要 AppleScript 中的一些帮助来执行此操作:在窗口或屏幕的某个点或区域中搜索,然后如果检测到 X 颜色按一个键,如果未检测到该颜色,则按另一个键。

我之前在 Autohotkey 中做过,但没有适用于 Mac 的版本,所以这就是我尝试在 AppleScript 中做的原因。

这是我如何在 Autohotkey 中获得它的示例:


坐标模式、像素、屏幕

动作 1: 找到X := 0 发现:= 0 PixelSearch, FoundX, FoundY, 1821, 1025, 1868, 1033, 0x666666, 3, 快速 如果(错误级别 = 1) 转到,Action2

Send, {F2}
Sleep, 133      
Send, {F3}
Sleep, 333
Goto, Action1 

动作 2: 找到X := 0 发现:= 0 PixelSearch, FoundX, FoundY, 1760, 1025, 1800, 1040, 0x5498FF, 5, 快速 如果(错误级别 = 1) 转到,操作1

Send, {F1}
Sleep, 333
Goto, Action1

【问题讨论】:

标签: macos colors window applescript screen


【解决方案1】:

您尝试击键 F2F3 键。 AFAIK,只能使用key code 触发 F 键,所以这是一个应该可以使用的版本。请注意,我对 Autohotkey 一无所知,因此您可能需要稍微调整一下代码:

try
    set theClipboard to the clipboard -- this just stores your clipboard for later use.
    set n to true
on error
    set n to false
end try
tell application "Digital Color Meter"
    launch
    tell current application to activate
    delay 0.1
    tell application "System Events"
        click menu item "Copy Colour as Text" of front menu of menu bar item "Colour" of front menu bar of application process "Digital Colour Meter"
        if (the clipboard) is equal to "255 255 255" then key code 160 -- If it doesn't work, try key code 99
    end tell
    quit
end tell
if n then set the clipboard to theClipboard

颜色以 RGB 存储,如果当前鼠标位置下的颜色为白色,则当前脚本按 F3

【讨论】:

    猜你喜欢
    • 2014-12-29
    • 1970-01-01
    • 2017-08-24
    • 2021-12-27
    • 1970-01-01
    • 2014-05-27
    • 1970-01-01
    • 1970-01-01
    • 2022-11-11
    相关资源
    最近更新 更多