Jump to content

Option tab to go to the previously used tab in a browser, very handy !


Recommended Posts

Posted

IDK how to share workflow as only images are accepted so here is the script to mimc ALT+TAB on a PC to use in a browser to go to the previously navigated tab, very handy: 

 

property lastTabFile : "/tmp/chrome_last_tab.txt"

on alfred_script(q)
    try
        tell application "Google Chrome"
            if not (exists front window) then
                return "No Chrome windows found"
            end if
            
            set tabCount to count tabs of front window
            if tabCount < 2 then
                return "Only one tab in the current window"
            end if
            
            set currentIndex to active tab index of front window
            
            -- Read the last tab index from file
            try
                set lastTabIndex to (do shell script "cat " & quoted form of lastTabFile) as number
            on error
                set lastTabIndex to 0
            end try
            
            -- If lastTabIndex is 0 or same as current, default to previous tab
            if lastTabIndex = 0 or lastTabIndex = currentIndex then
                set newIndex to currentIndex - 1
                if newIndex = 0 then set newIndex to tabCount
            else
                set newIndex to lastTabIndex
            end if
            
            -- Switch to the new tab
            set active tab index of front window to newIndex
            
            -- Save current tab index for next time
            do shell script "echo " & currentIndex & " > " & quoted form of lastTabFile
            
            set activeTabTitle to title of active tab of front window
            return "Switched to tab " & newIndex & ": " & activeTabTitle
        end tell
    on error errMsg
        return "Error: " & errMsg
    end try
end alfred_script

on run
    return alfred_script("")
end run

Posted (edited)

@xorq Most people use GitHub to share their workflows, see this blog post to help get you up and running: https://www.alfredapp.com/blog/guides-and-tutorials/share-workflow-on-github/

 

You should also check out this guide for documenting your workflow with some best practices for making it shareable: https://www.alfredapp.com/help/workflows/advanced/sharing-workflows/

 

Welcome to the community!

Edited by FireFingers21

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