在文本选择上触发Automator脚本


0

是否可以在Mac OS X上选择文本时触发Automator脚本?即如果我在任何应用程序中选择一些文本(例如Safari,Eclipse等),它应该触发Automator脚本。

我愿意接受使用其他语言/自动化程序的建议。

Answers:


1

如果应用程序像safari一样是可编写脚本的,那么您可以运行Applescript应用程序并检查是否有选择。然后通过运行任务或调用Automator工作流程进行响应。

选择文本时,Afaik应用程序不会发送通知,因此必须使用定期检查。这意味着当你的Applescript应用程序做出反应时,wthere应该是一个延迟

Applescript App的示例。 (保存为应用程序,保持打开状态)

    property oldSelectedText : ""


on idle
    try
        tell application "Safari"

            set selectedText to (do JavaScript "(''+getSelection())" in document 1)
            if selectedText is not "" then
                if oldSelectedText is not equal to selectedText then

                    (* DO STUFF*)

                    set oldSelectedText to selectedText
                    display notification with title "Safari Selection" subtitle selectedText

                end if
            end if
        end tell

    end try

    return 5 -- seconds idle before next check
end idle

谢谢。任何想法如何应用程序 PopClip 每当在任何应用程序中选择某些文本时,都会显示弹出菜单?期间检查?
— Franck Dernoncourt

抱歉不是一个线索,我担心它不是我将安装在我的机器上试图找出的应用程序。
— markhunte
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.