Is it possible to execute a web search in a background tab?
using terms from application "Quıcĸsıɩⅴεʀ"
on process text theText
tell application "Safari"
--activate
--tell first window to make new tab
search the web for theText --in last tab of first window
end tell
end process text
end using terms from
Not quite. I mean what I assumed `Open URL in Background` did. I
thought that action opened a new background tab. It doesn't, it just
doesn't activate the browser.
I'm looking for this sort of behavior:
http://www.makeuseof.com/tag/links-open-background-firefox-chrome/
(Web Search) ⇥ Search For… ⇥ (search text) ↩ No context switch with
the results in a new background tab.
using terms from application "Quıcĸsıɩⅴεʀ"
on process text theWebSearches with theSearchTerms
tell application "Safari"
if not (exists some window) then make new document
tell first window
repeat with theWebSearch in theWebSearches as list
set theSearchTerms to my urlEncode(theSearchTerms)
set theWebSearch to my findReplace("***", theSearchTerms, theWebSearch)
make new tab with properties {URL:theWebSearch}
end repeat
end tell
end tell
end process text
on get direct types
return {"Apple URL pasteboard type"}
end get direct types
on get indirect types
return {"NSStringPboardType"}
end get indirect types
on get argument count
return 2
end get argument count
end using terms from
on urlEncode(theSearchTerms)
return do shell script "php -r 'echo urlencode(\"" & theSearchTerms & "\");'"
end urlEncode
on findReplace(findText, replaceText, sourceText)
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to findText
set sourceText to text items of sourceText
set AppleScript's text item delimiters to replaceText
set sourceText to sourceText as text
set AppleScript's text item delimiters to ASTID
return sourceText
end findReplace
Caveats:1. You cannot use it to search multiple sites, since URLs selected with the comma trick are passed as an empty string (bug)
2. You cannot use it with multiple search terms selected with the comma trick — not even with 'Search For…' (bug?)
3. It doesn't change the third pane to text mode, although I set NSStringPboardType (bug?).
on process text theSearchTerms with theWebSearches
on get direct types
return {"NSStringPboardType"}
end get direct types
on get indirect types
return {"Apple URL pasteboard type"}
end get indirect types