Jump to content

Search Safari and Chrome Tabs [Updated Feb 8, 2014]


Recommended Posts

WebKit bug seems to be fixed (many thanks  :) ). I am not a huge fan of the previews; the icons look cleaner. Maybe it should be optional? At least until Alfred's feedback output system matures.

It uses the previews Safari generates, which usually end up getting squished by Alfred — they match the aspect ratio of your browser window, which usually won't fit into the square icons Alfred uses. I still think it's a good trade off as it makes it easier to find the tab you're looking for, but I do think it should be optional. I'll work on setting up a config file for this.

Link to comment

Off topic comment:

 

Wow! You know that tabbed browsing has really transformed the way we use the internet when you need a workflow to search through your open tabs. How did we ever manage to survive in the good old days of Internet Explorer?

Link to comment
  • 4 months later...
  • 2 weeks later...

I have some strange results in some more obscure Chrome usage scenarios:

 

  • Tab A is in a window on another Space, another Chrome window is inactive on the current space - when actioning Tab A the window on current space is brought to front, Space is unchanged. Another actioning (Alfred > Up > Enter) shows Tab A and pans to its Space as intended.
  • Tab A is in a window on another Space with another window, there is no Chrome window on current Space - when actioning Tab A I'm panned to the last focused window...and sometimes my Spaces reordered?!??!. Another actioning (Alfred > Up > Enter) shows Tab A as intended.
  • Tab A is in a minimized Chrome window in another Space - actioning Tab A pans to the correct Space, the window unminimizes and Tab A is focused, then for no apparent reason: I'm returned to the original Space. Another actioning (Alfred > Up > Enter) goes back to Tab A's Space (since it's now unminimized there.)

#1 is easily remedied by using "do shell script" then "activate". As noted in the code, this makes all Chrome windows come to front before switching to a tab :( ...this isn't ideal but it's better than the Space not switching or switching to the wrong window in another Space.

 

#2 gets weirder every time I try to fix and or/replicate it. I've lived with it since it doesn't come up all that much.
 
#3 is a beast. I've tried a few things to no avail. I've lived with it and the mentioned workaround.

 

Anyway, i just wanted to stop by and thank you for all your hard work. Looks like you've got a good amount of time into it.

 

I wouldn't worry about these cases too much, just figured I'd leave them here.

Edited by sudopeople
Link to comment
  • 3 weeks later...

Hi, this workflow isn't working for me, it doesn't return any tab. I'm on Mavericks, so maybe it has something to do with that.

I've tried running the search_tabb.rb script from terminal, to se the output error, and is this.

 

 

$ /usr/bin/ruby search_tabs.rb
 
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- alfred (LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'

 

from search_tabs.rb:17:in `<main>'

 

The version of ruby shipped with Mavericks is this one

 

$ /usr/bin/ruby -v

 

ruby 2.0.0p247 (2013-06-27 revision 41674) [universal.x86_64-darwin13]

 

Any ideas? It seems such an incredible useful workflow you have here, I 'd really like to have it working! 

Link to comment

Hi, this workflow isn't working for me, it doesn't return any tab. I'm on Mavericks, so maybe it has something to do with that.

I've tried running the search_tabb.rb script from terminal, to se the output error, and is this.

 

 

The version of ruby shipped with Mavericks is this one

 

Any ideas? It seems such an incredible useful workflow you have here, I 'd really like to have it working! 

 

D'oh, was meaning to check if it would work with Ruby 2.0.0. Thanks for the heads up. I updated the original post with a new download that should hopefully fix that.

 

I have some strange results in some more obscure Chrome usage scenarios:

 

  • Tab A is in a window on another Space, another Chrome window is inactive on the current space - when actioning Tab A the window on current space is brought to front, Space is unchanged. Another actioning (Alfred > Up > Enter) shows Tab A and pans to its Space as intended.
  • Tab A is in a window on another Space with another window, there is no Chrome window on current Space - when actioning Tab A I'm panned to the last focused window...and sometimes my Spaces reordered?!??!. Another actioning (Alfred > Up > Enter) shows Tab A as intended.
  • Tab A is in a minimized Chrome window in another Space - actioning Tab A pans to the correct Space, the window unminimizes and Tab A is focused, then for no apparent reason: I'm returned to the original Space. Another actioning (Alfred > Up > Enter) goes back to Tab A's Space (since it's now unminimized there.)

#1 is easily remedied by using "do shell script" then "activate". As noted in the code, this makes all Chrome windows come to front before switching to a tab :( ...this isn't ideal but it's better than the Space not switching or switching to the wrong window in another Space.

 

#2 gets weirder every time I try to fix and or/replicate it. I've lived with it since it doesn't come up all that much.

 

#3 is a beast. I've tried a few things to no avail. I've lived with it and the mentioned workaround.

 

Anyway, i just wanted to stop by and thank you for all your hard work. Looks like you've got a good amount of time into it.

 

I wouldn't worry about these cases too much, just figured I'd leave them here.

 

Hmm, interesting. Tested it out and it is indeed acting strange (only tested it on Mountain Lion so far). Thanks for letting me know about it.
 
I went ahead and implemented your fix for the first scenario. Also fixed some issues where the workflow occasionally wouldn't focus the correct window. Still not sure what to do about the other two scenarios, but I'll keep playing around with it.
Link to comment

 

D'oh, was meaning to check if it would work with Ruby 2.0.0. Thanks for the heads up. I updated the original post with a new download that should hopefully fix that.

 

 

 

Thanks for updating it so quickly!

It is indeed working now, but not always. I haven't been able to find the exact problem, but depending the websites I have opened, sometimes the workflow doesn't find any tabs via Alfred. 

 

It doesn't matter if they are open in chrome or safari. For example, www.elotrolado.net or www.elmundo.es. If any of this webpages is loaded in a tab, the workflow won't return any result, but if they aren't the workflow will work just fine.

 

I haven't been able to find what could be wrong with this websites.

 

If I launch the ruby script myself via /usr/bin/ruby search_tabs "" it will return results ok, even those problematic websites..

 

If you need any help finding the problem just ask,  or If I manage to fix it (I'll try this weekend if I have free time before formula1 :P) I'll post the solution.

 

Thanks for everything!

Edited by asendra
Link to comment

Thanks for updating it so quickly!

It is indeed working now, but not always. I haven't been able to find the exact problem, but depending the websites I have opened, sometimes the workflow doesn't find any tabs via Alfred. 

 

It doesn't matter if they are open in chrome or safari. For example, www.elotrolado.net or www.elmundo.es. If any of this webpages is loaded in a tab, the workflow won't return any result, but if they aren't the workflow will work just fine.

 

I haven't been able to find what could be wrong with this websites.

 

If I launch the ruby script myself via /usr/bin/ruby search_tabs "" it will return results ok, even those problematic websites..

 

If you need any help finding the problem just ask,  or If I manage to fix it (I'll try this weekend if I have free time before formula1 :P) I'll post the solution.

 

Thanks for everything!

 

All right, think I got it fixed this time. There was an issue with string encoding (which is why those Spanish language websites were causing problems), but I've just updated the workflow and it seems to be working now. Let me know if you encounter any other issues.

Link to comment

All right, think I got it fixed this time. There was an issue with string encoding (which is why those Spanish language websites were causing problems), but I've just updated the workflow and it seems to be working now. Let me know if you encounter any other issues.

 

Thanks again, it works!!

 

I supposed it was something like that, that was the first thing I was going to try tomorrow.

 

This really saves the day when you have +20 tabs open simultaneously.

Link to comment
  • 2 weeks later...

Clinton, 

 

I ran across your workflow while working on one of my own, so I combined them. I don't want to post it here, because it's mostly your work. If you want it, I can send it to you or post it here. The two features changes are 1) the workflow recognized shortcuts to tabs and 2) the search results for those shortcuts includes an option to open a new tab in the default browser

 

I've got shortcuts for Google Mail (gm), Google Calendar (gc), etc. So typing in "tabs gc" translates to "tabs google calendar".

 

Case 1: Tab is already open. "tabs gc" returns 2 results. The first result is the open tab. The second result is "Open New Google Calendar".

 

Case 2: Tab not found. "tabs gc" returns 1 results. The first result is "Open New Google Calendar".

 

The idea is to just type "tabs gc" hit return and always see my calendar. Not sure if Alfred's learning with switch the "Open New ..." line to the #1 position.

 

Let me know if you want these changes.

Link to comment

Clinton, 

 

I ran across your workflow while working on one of my own, so I combined them. I don't want to post it here, because it's mostly your work. If you want it, I can send it to you or post it here. The two features changes are 1) the workflow recognized shortcuts to tabs and 2) the search results for those shortcuts includes an option to open a new tab in the default browser

 

I've got shortcuts for Google Mail (gm), Google Calendar (gc), etc. So typing in "tabs gc" translates to "tabs google calendar".

 

Case 1: Tab is already open. "tabs gc" returns 2 results. The first result is the open tab. The second result is "Open New Google Calendar".

 

Case 2: Tab not found. "tabs gc" returns 1 results. The first result is "Open New Google Calendar".

 

The idea is to just type "tabs gc" hit return and always see my calendar. Not sure if Alfred's learning with switch the "Open New ..." line to the #1 position.

 

Let me know if you want these changes.

 

Sure, feel free to post it here.
 
I've been thinking about how to make the workflow more flexible, especially with finding pages that aren't already open. I was thinking about having it fall back to a history search if you add a character to the end (maybe an exclamation mark). So you could type "cal" to search for Google Calendar, and if it's not open, you can type "cal!" to search it in your browser history. But I do like your idea. I'm interested to see how you implemented it.
 
I'll work on refactoring the code and then play around with adding new features. This was the first Ruby code I ever hacked together, so it could use some work.
Link to comment

Ugh, upgraded to Maverick and the workflow stopped working. I tried to go back to your original and that's not working either. I think there was some Ruby change in Maverick. Feel like a kid who had his present break on his birthday. "Yipppeeeeeee, it works.....awwwww"

 

Here is the link: https://dl.dropboxusercontent.com/u/1192535/Search%20Browser%20Tabs_Curtis.alfredworkflow

 

Search_tabs.rb

  • Line 23 Added shortcuts hash and used it to replace the query string if it matches
  • Line 118 If query was a shortcut, add 1 row to the results to open up blank tab
  • I slightly changed the format of the argument. Put in new field to know if this is activating an existing tab or opening a new one.

get_default_browser.applescrip - Script to get default browser to set icon in results window. Used in search_tabs.rb

 

activate_tab.rb - if/then to either activate a tab or open a new one.

 

**Disclaimer** When I found out Maverick broke the workflow, I spent a little time trying to debug. I think I reset the code to my working version from a couple days ago, but since all my machines are now Maverick, I cannot test. When I get some time, I'll get back to this.

Link to comment

Back to blaming Mavericks. I downloaded your original version and that works. Your second version does not work and that is the workflow that I extended. My extended version also doesn't work. I'm not a ruby guy, so any debugging is going to have to wait until I have more time. 

Link to comment

Dropbox link has fixed code. Apparently, Maverick has new version of Ruby and Ruby no longer uses current directory in search path. Just needed a ./ on the require.

 

require "./alfred"

 

As I mentioned before, I'm not a ruby dev so I was not sure how to debug ruby in Alfred. Then realized you were sending errors to output.log <facepalm> Figured out the error immediately after seeing that log.

 

Link to the explanation of the ruby change.

http://stackoverflow.com/questions/2900370/why-does-ruby-1-9-2-remove-from-load-path-and-whats-the-alternative

Link to comment

Dropbox link has fixed code. Apparently, Maverick has new version of Ruby and Ruby no longer uses current directory in search path. Just needed a ./ on the require.

 

require "./alfred"

 

As I mentioned before, I'm not a ruby dev so I was not sure how to debug ruby in Alfred. Then realized you were sending errors to output.log <facepalm> Figured out the error immediately after seeing that log.

 

Link to the explanation of the ruby change.

http://stackoverflow.com/questions/2900370/why-does-ruby-1-9-2-remove-from-load-path-and-whats-the-alternative

 

Nice, thanks for the workflow. I'll look in to maybe adding a config file for adding custom shortcuts. I like the idea!

Link to comment
  • 2 weeks later...

Sorry about that. Try double clicking the script filter in Alfred Preferences and set the script to this:

/usr/bin/ruby search_tabs.rb "{query}" 2> ~/Desktop/errorlog.txt

Try typing 'tabs' into Alfred again, then check your Desktop for an errorlog.txt file. Let me know if any error messages were logged there.

 

I just did. No error log. The errorlog.txt file is empty.

Link to comment

I just did. No error log. The errorlog.txt file is empty.

 

Just so I can figure out if it's a problem with the AppleScript part of the workflow, could you open up AppleScript Editor, create a new document and see if this code runs? (You'll need to have Chrome open.)

on run argv
    set theOutput to ""
    set windowIndex to 1
    
    tell application "Google Chrome"
        repeat with theWindow in windows
            try
                set tabIndex to 1
                repeat with theTab in tabs of theWindow
                    set theOutput to ((theOutput & windowIndex as string) & ":" & tabIndex as string) & "
" & URL of theTab & "
" & title of theTab & "
"
                    set tabIndex to tabIndex + 1
                end repeat
            end try
            set windowIndex to windowIndex + 1
        end repeat
    end tell
    
    theOutput
end run

You should see something like this in the output if it's working properly:

"1:1
https://www.google.com/
Google
1:2
http://www.alfredforum.com/forum/3-share-your-workflows/
Share your Workflows - Alfred App Community Forum
1:3

Search Safari and Chrome Tabs - Share your Workflows - Alfred App Community Forum
"

Also, does it get stuck on "Retrieving tabs...", or does it eventually show your fallback results? And what version of OS X are you running?

Link to comment

Just so I can figure out if it's a problem with the AppleScript part of the workflow, could you open up AppleScript Editor, create a new document and see if this code runs? (You'll need to have Chrome open.)

on run argv
    set theOutput to ""
    set windowIndex to 1
    
    tell application "Google Chrome"
        repeat with theWindow in windows
            try
                set tabIndex to 1
                repeat with theTab in tabs of theWindow
                    set theOutput to ((theOutput & windowIndex as string) & ":" & tabIndex as string) & "
" & URL of theTab & "
" & title of theTab & "
"
                    set tabIndex to tabIndex + 1
                end repeat
            end try
            set windowIndex to windowIndex + 1
        end repeat
    end tell
    
    theOutput
end run

You should see something like this in the output if it's working properly:

"1:1
https://www.google.com/
Google
1:2
http://www.alfredforum.com/forum/3-share-your-workflows/
Share your Workflows - Alfred App Community Forum
1:3

Search Safari and Chrome Tabs - Share your Workflows - Alfred App Community Forum
"

Also, does it get stuck on "Retrieving tabs...", or does it eventually show your fallback results? And what version of OS X are you running?

 

Done - http://d.pr/i/F8Ab 

It gets stuck on "Retrieving tabs...".

Link to comment

This workflow + 1Password are completely awesome.  1Password has these 1 click bookmarks that will jump to a web page and log you in if it's required. I figured out if I gave 1Password and this workflow the same keyword, that they will give me both results in the Alfred list.

 

I tweaked the workflow a little more. Here's what it does now.

 

  • Changed keyword to "go". Just easier for me to type.
  • Changed 1Password keyword to "go". This combines the output of this workflow and 1Password. Check out the screenshot.
  • "go " shows my shortcut app list that I use all the time. Though after combining this workflow with 1Password, it might not be that useful.
  • "go " + [any text] searches all browser tabs plus 1Password for sites that match [any text]. See the screen shot.
  • [Command]+[Enter] runs an applescript to open alfred and type "go "

I'm finding I hardly have to take my fingers off the keyboard. And instead of bookmarks, I'm loading these URLs into 1Password, whether they need UID/Password or not.

 

Link to the workflow. I feel like I've forked your code, but I don't want to share it under a different name and don't want to share my changes under your name. Feel free to include any of my changes into your wordflow.

 

https://dl.dropboxusercontent.com/u/1192535/Go%20to%20browser%20tab.alfredworkflow

 

 

Screenshot%202013-11-07%2010.21.40.png

Edited by Curtis
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...