2011-08-03 32 views
1

我嘗試使用以下方法來打開Spotlight搜索框:Applescript推出Spotlight?

tell application "System Events" 
    keystroke " " using {command down} 
end tell 

它只是試圖發出命令空間。它確實有效,但如果我將該腳本另存爲應用程序並運行它,Spotlight窗口將顯示出來,然後立即消失。

爲什麼會發生這種情況,我該如何保持Spotlight窗口打開?

或者:如何使用Applescript打開Spotlight搜索框?

回答

1

您的腳本打開Spotlight 菜單。打開聚光燈窗口鍵盤快捷鍵爲命令 + 選項 + 空間 ......

tell application "System Events" to keystroke space using {command down, option down} 

UPDATE:鑑於你的答案修訂,我已經由一個小腳本,應該做的你想要什麼?

set the searchText to the text returned of (display dialog "Enter the name of an item you wish to search for in Spotlight:" default answer "") 
tell application "System Events" 
    keystroke space using {command down} 
    keystroke the searchText 
    --[1] 
end tell 

你可以在[1]以下情況之一:

  • 打開最高命中:

    keystroke return using {command down} 
    
  • 移動選擇的第一個項目中的一個類別:

    keystroke (ASCII character 31) using {command down} --down arrow 
    
  • 移動選擇的第一個項目中的一個類別:

    keystroke (ASCII character 30) using {command down} --up arrow 
    
  • 移動選擇的第一個項目在整個菜單:

    keystroke (ASCII character 31) using {control down} 
    
  • 移動選擇到最後一個項目在整個菜單:

    keystroke (ASCII character 30) using {control down} 
    
+0

好。錯誤的術語。我正在尋找腳本來打開_menu_。 – Snoqual

+0

這是否意味着無法通過Applescript保持Spotlight搜索框打開?我正在尋找的是沒有另一個窗口。我想要打開Spotlight搜索框並將光標置於搜索框中,以供用戶輸入。 – Snoqual

+0

據我所知,您不能保持Spotlight窗口與AppleScript打開。對不起。你有沒有試過我的腳本? – fireshadow52

0

簡單的增加一個延遲。

 tell application "System Events" 
     keystroke " " using {command down} 
     delay 5 
     delay 5 
    end tell 

或者萬無一失這樣的: