2014-02-28 37 views
1

任何人都知道如何在使用AppleScript的郵件應用程序中使用搜索欄?我想使用Mail應用程序中的搜索欄自動執行搜索主題(而不是搜索整個郵件)的過程。由於我想搜索所有的郵箱(收件箱除外,還有其他的智能郵箱),我不能使用常用的方式,這是設置郵箱,然後通過裏面的所有消息。謝謝你的幫助。如何在使用Applescript的郵件應用程序中使用搜索欄?

回答

2

您可以使用稱爲GUI腳本的技術,它使您能夠直接訪問ui小部件並使用它們執行操作。

給這個腳本一試:(更改搜索文字,你需要什麼)

activate application "Mail" 

tell application "System Events" 
    tell process "Mail" 
     tell window 1 

      set search_text_field to text field 1 of the last group of tool bar 1 

      tell search_text_field 
       set the value of attribute "AXValue" to "subject:congratulations" 
       key code 36 -- press RETURN key 
      end tell 

     end tell 
    end tell 
end tell 

(它爲我在10.7,可能無法在近期OS)

+0

這幾乎適用於我在優勝美地,但搜索條件不解析和激活。該字符串出現,但然後停止。我認爲這可能與搜索框中的鼠標綁定有關。有什麼辦法可以模仿嗎? –

+0

@ChrisQuenelle嘗試在「keycode 36」之前加入一行:「delay 1」,在優勝美地修復它。歡呼 – adamh

+0

真棒,作品像魅力!謝謝@adamh! –

0

對於我來說,這在優勝美地沒有工作。 我使用了這種解決方法:

activate application "Mail" 

tell application "System Events" 

    tell process "Mail" 

     tell window 1 

      keystroke "f" using {command down, option down} 

      keystroke *your variable* as string 

     end tell 

    end tell 
end tell 
相關問題