2011-09-27 41 views
2

我想写一个苹果纸条搜索麻雀(邮件客户端适用于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 

的问题是,我想脚本拍摄一个关于运行的论点,以便我可以提供搜索的内容,但是我无法将其解决。

回答

2
  1. argv总是初始化列表。
  2. 你不能击键列表(你必须先强制​​每个项目到一个字符串)。
  3. 你永远无法知道的,将被发送到脚本参数的确切数字,所以更好的路线是通过列表进行迭代,做任何需要做的事情,如下图所示:

    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 
    

@Runar

  1. 脚本是暗示麻雀已经被激活。
  2. 你不能这样写(every text item of argv的结果仍然是一个列表)。但是,如果将结果强制转换为字符串,这将起作用,但它会将所有内容挤在一起(假设AppleScript's text item delimiters"")。如果您set AppleScript's text item delimiters to space,那么这实际上是比以前更好的剧本......

    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 
    
+0

确定。你的脚本不会激活麻雀,所以密钥不会被发送到正确的应用程序。我可以做“keystroke(every item go agrv)? – Runar

+0

@Runar查看我的编辑 – fireshadow52

+0

谢谢,现在看起来不错,但剧本需要s来激活Sparrow,脚本的要点是从Alfred开始。 – Runar