Search in background tab?

130 views
Skip to first unread message

Tim Visher

unread,
Dec 12, 2013, 10:51:42 AM12/12/13
to blacktree-...@googlegroups.com
Hey Everyone,

Is it possible to execute a web search in a background tab?

Thanks in advance!

--

In Christ,

Timmy V.

http://blog.twonegatives.com/
http://five.sentenc.es/ -- Spend less time on mail

1.61803

unread,
Dec 12, 2013, 8:16:28 PM12/12/13
to blacktree-...@googlegroups.com
On Thursday, December 12, 2013 4:51:42 PM UTC+1, Tim Visher wrote:
Is it possible to execute a web search in a background tab?

If you mean to perform a general web search with your default search engine use the following applescript action, uncomment to run it in a new background tab a/o to activate Safari. I don't know if you could make both alternatives of each other, maybe the devs can chime in.

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

Tim Visher

unread,
Dec 13, 2013, 8:17:32 AM12/13/13
to blacktree-...@googlegroups.com
On Thu, Dec 12, 2013 at 8:16 PM, 1.61803 <iam...@gmail.com> wrote:
> On Thursday, December 12, 2013 4:51:42 PM UTC+1, Tim Visher wrote:
>>
>> Is it possible to execute a web search in a background tab?
>
>
> If you mean to perform a general web search with your default search engine
> use the following applescript action, uncomment to run it in a new
> background tab a/o to activate Safari. I don't know if you could make both
> alternatives of each other, maybe the devs can chime in.

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/

1.61803

unread,
Dec 13, 2013, 9:27:25 AM12/13/13
to blacktree-...@googlegroups.com
On Friday, December 13, 2013 2:17:32 PM UTC+1, Tim Visher wrote:
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/

What's exactly your use case? I understand you want to open an URL in a background tab. Some URL, a generic web search, a specific search? or use QS's Search For… / Find With… actions? Should the browser be active or activate? Some of these options you can accomplish with the script I posted or modify it accordingly.

Tim Visher

unread,
Dec 13, 2013, 10:05:23 AM12/13/13
to blacktree-...@googlegroups.com
(Web Search) ⇥ Search For… ⇥ (search text) ↩ No context switch with
the results in a new background tab.

1.61803

unread,
Dec 13, 2013, 1:42:35 PM12/13/13
to blacktree-...@googlegroups.com
On Friday, December 13, 2013 4:05:23 PM UTC+1, Tim Visher wrote:
(Web Search) ⇥ Search For… ⇥ (search text) ↩ No context switch with
the results in a new background tab.

Let me know if this applescript action works for you.
You could name it 'Search For… in Background', use the default action icon and rank it higher than 'Search For…'.
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?).

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

1.61803

unread,
Dec 18, 2013, 8:46:47 AM12/18/13
to blacktree-...@googlegroups.com
On Friday, December 13, 2013 7:42:35 PM UTC+1, 1.61803 wrote:
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?).



If anyone wants to use this action the other way as in Find With… just change

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

Reply all
Reply to author
Forward
0 new messages