Search code examples
google-chromeapplescriptgoogle-search

OSX script for triggering Google Chrome's Voice Search keyboard shortcut


In the Google Chrome browser (on a mac), you can activate the Google Voice Search by pressing Command+Shift+Period from htttp://google.com.

Assuming the url http://google.com is loaded in a chrome tab with the search box in focus, shouldn't the following applescript work?

tell application "Google Chrome"
    activate
    tell application "System Events" to keystroke "." using {command down, shift down}
end tell

For some reason it won't work, and I don't understand why because the following script will fill the search field with text as expected:

tell application "Google Chrome"
    activate
    tell application "System Events" to keystroke "this test works as expected"
end tell

How can I trigger the google voice search with a script?


Solution

  • Try:

    tell application "Google Chrome" to activate
    tell application "System Events"
        key code 47 using {command down, shift down}
    end tell
    delay 3