【问题标题】:How can I detect whether something is selected with AppleScript?如何检测是否使用 AppleScript 选择了某些内容?
【发布时间】:2017-09-11 01:41:08
【问题描述】:

我正在使用一些名为 controllermate 的软件,它允许您自定义键盘或鼠标上按钮的行为。您可以在苹果脚本中的特定功能中使用的“构建块”之一。我想为我的鼠标创建一个自定义行为,如果当前选择了可以复制的内容,则某个按钮将执行 CMD+C,否则执行不同的键盘快捷键。看来我必须使用appleScript来确定是否选择了文本,但是在阅读了其他一些人的在线解决方案后,我无法弄清楚如何自己实现它。谢谢你的帮助。

【问题讨论】:

    标签: text applescript selection detect


    【解决方案1】:

    这里有一个解决方案:

    将一个空字符串放入剪贴板,执行CMD+C,检查剪贴板。

    set the clipboard to ""
    tell application "System Events" to keystroke "c" using command down
    delay 0.2
    
    set b to false
    try
        set b to (the clipboard as string) is not ""
    on error -- error when the clipboard contains a custom type (like a copy in the Photos Application)
        set b to true
    end try
    if b then -- the clipboard does not contains an empty string
        -- *** script to execute a different keyboard shortcut ***
        --tell application "System Events" to keystroke someChar using someModifier
    end if
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-22
      • 1970-01-01
      相关资源
      最近更新 更多