How to launch an Amazon search using the contents of the clipboard

I'd like to be able to select and copy some text, then press a button and Amazon.com loads in a new tab and searches with my newly copied text.

Is this possible?

There might be an easier or less cumbersome way to do this but the following seems to work. Just use an Run Apple Script as the predefined action


tell application "Safari"
activate
open location "http://www.amazon.com"

-- key code 48 is tab. From what I can tell 5 tabs gets to the search box. May need to adjust delay or number of tabs. 
-- found the key code numbers here - https://macbiblioblog.blogspot.com/2014/12/key-codes-for-function-and-special-keys.html
delay 4
tell application "System Events" to key code 48
tell application "System Events" to key code 48
tell application "System Events" to key code 48
tell application "System Events" to key code 48
tell application "System Events" to key code 48
delay 1
-- key code 9 is "v" so the next line is paste
tell application "System Events" to key code 9 using (command down)
-- key code 36 is return
tell application "System Events" to key code 48
tell application "System Events" to key code 36

end tell


The easiest way to do it would be to use the predefined action "Open URL / Open URL with selection".
Every %@ in the url will be replaced by the currently selected text, or if nothing is selected, the contents of your clipboard.

Thanks! I didn't realise that it could do that. So for eranbeard's button it would be


"https://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=%@"


and then any text copied or selected would be searched?

Yes, that should work :slight_smile:

Fantastic thank you Doa and Andreas!