1

以下を使用して Spotlight 検索ボックスを開こうとしました。

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

コマンドスペースを発行しようとするだけです。動作しますが、スクリプトをアプリケーションとして保存して実行すると、Spotlight ウィンドウが表示され、その後すぐに消えます。

これはなぜですか?また、Spotlight ウィンドウを開いたままにするにはどうすればよいですか?

別の方法: Applescript を使用して Spotlight 検索ボックスを開くにはどうすればよいですか?

4

2 に答える 2

1

スクリプトによって Spotlightメニューが開きます。Spotlightウィンドウを開くためのキーボード ショートカットはcommand+ option+ space...

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

更新:あなたの修正された答えを考慮して、私はあなたが望むことをする小さなスクリプトを作成しました...

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}
    
于 2011-08-04T00:46:23.000 に答える