I would like to set-up a single BTT button to open a URL in a new browser tab, adding selected text to the end of the URL, however the base URL used will be different depending on the first two letters of the user's selected text. Examples below:
- "selected text = AA111" opens new tab in browser to "url_for_website1/search?q=AA111"
- "selected text = BB222" opens new tab in browser to "url_for_website2/search?q=BB222"
- "selected text = CC333" opens new tab in browser to "url_for_website3/search?q=CC333"
Below is Apple script that seems to work in an Automator service. Can anyone guide me as to how I could port this to a BTT button?
Many thanks in advance for any help from the community.
on run {input, parameters}
-- Identify first two letters (example, AA / BB / CC) to match to desired base URL, then append the selected text to the end of the URL:
if (input as string) begins with "AA" then
open location "https://www.google.com/search?q=" & input
return
end if
if (input as string) begins with "BB" then
open location "https://www.bing.com/search?q=" & input
return
end if
if (input as string) begins with "CC" then
open location "https://duckduckgo.com/?q=" & input
return
end if
end run