Applescript 粘贴问题

Applescript 粘贴问题,applescript,Applescript,我正试着写一份苹果纸条来搜索Sparrow(Mac的邮件客户端) 以下是脚本: on run argv tell application "Sparrow" activate end tell tell application "System Events" key code 3 using {option down, command down} keystroke argv end tell end run

我正试着写一份苹果纸条来搜索Sparrow(Mac的邮件客户端)

以下是脚本:

 on run argv

    tell application "Sparrow"
        activate
    end tell

    tell application "System Events"
        key code 3 using {option down, command down}
        keystroke argv
    end tell
end run
问题是,我希望脚本在运行时获取一个参数,以便为它提供搜索内容,但我无法让它粘贴出来

  • argv
    始终初始化为列表
  • 不能键入列表(必须先将每个项强制为字符串)
  • 您永远无法知道将发送到脚本的参数的确切数量,因此更好的方法是遍历列表并执行需要执行的操作,如下所示:

    tell application "System Events"
        tell process "Sparrow"
            key code 3 using {command down, option down}
            repeat with this_item in argv
                keystroke (this_item as string)
            end repeat
        end tell
    end tell
    

  • @鲁纳尔

  • 脚本暗示Sparrow已经激活
  • 您无法按编写的方式执行此操作(argv的
    每个文本项的结果仍然是一个列表)。但是,如果将结果强制为字符串,这将起作用,但它会将所有内容压缩在一起(假设
    AppleScript的文本项分隔符
    )。如果
    将AppleScript的文本项分隔符设置为空格
    ,那么这实际上比以前的脚本要好

    on run argv
        tell application "Sparrow" to activate
        tell application "System Events"
            tell process "Sparrow" --implying Sparrow is already activated
                set prevTIDs to AppleScript's text item delimiters
                key code 3 using {command down, option down}
                set AppleScript's text item delimiters to space
                keystroke (every text item of argv) as string
                set AppleScript's text item delimiters to prevTIDs
            end tell
        end tell
    end run
    

  • 好啊您的脚本未激活sparrow,因此密钥代码不会发送到正确的应用程序。我可以做“击键(每一项都会变为agrv)”吗?谢谢。现在看起来不错。但是脚本需要s来激活Sparrow。脚本的重点是从Alfred那里启动它。非常感谢!工作就像一个符咒。Mad fit加入了一个扩展,并将您视为编码员。希望您不介意。