Jump to content
loris

"Open url" feature being aware of already opened tabs

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites

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