Jump to content

Run Browser Web Search in the Background


Recommended Posts

Howdy Fellow Alfred-itors!

 

I've been trying to figure out how I could modify Alfred's awesome keyword / search engine feature to enable me to do a Google search in a new background tab—i.e., *without* automatically shifting from my current browser tab (or current application) to the new browser tab where the search opens, as Alfred does by default.  There were a few forum posts over the years from users seeking this feature—but none of them was satisfactorily answered… Ha, but since I managed to figure out a workaround riiiiiight before I was about to give up, I thought I'd pay it forward and post it here —> since perhaps there are other users who'd like to enable to this search-in-background feature.

 

This workflow enables you to (1) search Google using Alfred while browsing in Safari in a new background tab—as well as (2) to stay in a different (i.e., non-Safari) app and run the Google search entirely in the background… which can be helpful if you're, say, poring over an Excel spreadsheet and you want to remember to Google search something later—but don't want your focus to get yanked away from your current work.

 

It's a simple two-step workflow design:

 

1101740476_Screenshot2018-08-1915_38_03.png.ffd0d095cff66956236ecbc1b7b0b8b3.png 

 

INPUTS = "Keyword" —> ACTIONS = "Run Script"

 

NOTE:  You must select "/usr/bin/osacript (AS)" from the "Language" drop-down menu on the script action—and then select "with input as {query}" from the adjacent drop-down.

 

Here is the Applescript to enter into the "Script" box:

set myURL to "https://www.google.com/search?q={query}"

tell application "Safari"
	tell front window
		make new tab at end of tabs with properties {URL:myURL}
	end tell
end tell

 

 

And finally, here are screen-grabs of how I configured both workflow items:

 

943002854_Screenshot2018-08-1916_02_05.png.f64603bf88d153703dc52ad06cbf7935.png

 

1544641214_Screenshot2018-08-1915_38_27.png.14076d05f06b43de5686769a8113d395.png  

 

 

I hope someone out there finds this helpful!

 

Cheers,

 

—Michael

Link to post

For those who prefer Google Chrome over Safari, here's the alternative AppleScript that should enable the same background search features in Chrome:

 

set myURL to "https://www.google.com/search?q={query}"

tell application "Google Chrome"
	set activeIndex to get active tab index of window 1
		tell window 1
			set newTab to make new tab with properties {URL:myURL}
		end tell
		set active tab index of window 1 to activeIndex
end tell

 

—Michael

Edited by AvantGardener
Link to post
  • 5 months later...
  • 1 month later...
  • 9 months later...
On 8/20/2018 at 7:17 AM, AvantGardener said:

set activeIndex to get active tab index of window 1

I made the workflow exactly as you did, but it doesn't stay in the app and goes to Google Chrome, although it remains at the previous tab and let the tab searching google in background. 

 

Any suggestions? Thanks.

 

Link to post

Thanks a lot, deanishe! Though I'm not able to add code, since I don't know how to program🙄. Would you, or anyone else, be able to help me modify the code so that I can make the web search in the currently-active app and let Chrome search in background? I would much appreciate!  

Link to post

@asphoa There you go. This alternative Workflow works by opening the search in the browser then switching to the app that was frontmost.


It has the disadvantage that there’s a short “flash” of the browser’s window being brought to the front and then back, but it has a few advantages as well: it doesn’t depend on a browser’s AppleScript dictionary, so there’s no need to add permissions for it and will keep working even if the dictionary changes; works for any browser (even Firefox); if you change your default browser, no need to modify the Workflow.

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...