Jump to content

"Open url" feature being aware of already opened tabs


loris

Recommended Posts

I use Alfred for a freaking lots of actions and that's why I love it so much, but my primary use (and I'm pretty sure that's the case of most Alfred users) is to use it as an Application Launcher.

However lots of applications nowadays are web apps: Gmail, Facebook, Google Reader, Deezer, Remember the milk,...

The issue I have when using Alfred to launch web app is that I can't switch to one of them if it's already opened, Alfred would launch a new duplicate tab.

For instance, when using "Open Gmail" action in Alfred, I would love to have it check first if my default browser already has Gmail opened in any tabs and then would just switch to this tab instead.

I know this can be kind of done using Applescript but it would be awesome to have this feature built-in as an option in the "Open url" feature

Link to comment
Share on other sites

I'm not sure if this feature will come to Alfred, but in the meanwhile here's some AppleScript that could do it:

 

Safari:

on alfred_script(q)
    set windowIndex to 1

    tell application "Safari"
        repeat with theWindow in windows
            set tabIndex to 1
            repeat with theTab in tabs of theWindow
                if url of theTab is q then
                    activate
                    tell theWindow
                        set current tab to tab tabIndex
                        set index to 1
                    end tell
                    tell application "System Events" to tell process "Safari"
                        perform action "AXRaise" of window 1
                    end tell
                    return
                end
                set tabIndex to tabIndex + 1
            end repeat
            set windowIndex to windowIndex + 1
        end repeat
    end tell

    open location q
end alfred_script

 

Chrome:

on alfred_script(q)
    set windowIndex to 1

    tell application "Google Chrome"
        repeat with theWindow in windows
            set tabIndex to 1
            repeat with theTab in tabs of theWindow
                if url of theTab is q then
                    activate
                    tell window windowIndex
                        set active tab index to tabIndex
                        set index to 1
                    end tell
                    tell application "System Events" to tell process "Google Chrome"
                        perform action "AXRaise" of window 1
                    end tell
                    return
                end
                set tabIndex to tabIndex + 1
            end repeat
            set windowIndex to windowIndex + 1
        end repeat
    end tell

    open location q
end alfred_script

 

You might have to make some modifications to make it work how you want, as it only matches exact URLs.

Link to comment
Share on other sites

  • 4 years later...

Old post, but just adding this here in case it helps someone (thanks for the scripts by the way!).

 

It's easy enough to change the scripts so it doesn't have to be an exact match of the URL. Just change the following line:

if url of theTab is q then

to this:

if q is in url of theTab then

 

Link to comment
Share on other sites

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...