Can You Move/Arrange a Finder Tab With Applescript?

What’s the best way to move a Finder tab to the left/right with Keyboard Maestro?

I’m hoping it’s possible to do this via Applescript without resorting to found image triggers.

Hey Jay,

AppleScript cannot manipulate tabs.

But it can locate the position of the tabs using GUI-Scripting via System Events.

tell application "System Events"
  tell application process "Finder"
    tell front window
      set tabCount to count of radio buttons
      tell radio button 1
        set button1Position to value of attribute "AXPosition"
      end tell
      tell radio button 2
        set button2Position to value of attribute "AXPosition"
      end tell
      tell radio button 3
        set button3Position to value of attribute "AXPosition"
      end tell
    end tell
  end tell
end tell

From there you may be able to drag & drop them with Keyboard Maestro.

-Chris

Thanks for the reply Chris. I’m not really sure where this would get me though :confused:

Hey Jay,

Using AppleScript and System Events you can gather the position and size of the tabs.

From there you can possibly get Keyboard Maestro to drag and drop them for you.

But it’s not an easy task.

-Chris

OK, thanks for the suggestion though!
Sounds a bit complex for my programming abilities and prob not worth it. Shame that the Finder tabs are not more accessible.

Hey Jay,

True.   :smile:

You could change the target of the tabs though, and that wouldn’t be nearly as hard.

Create a window in the Finder with more than one tab, and then run the following AppleScript from the Script Editor.app.

------------------------------------------------------------

set tabTargetList to {}

tell application "System Events"
  tell application process "Finder"
    set frontmost to true
    tell (first window whose subrole is "AXStandardWindow")
      set radioButtonList to name of its radio buttons
    end tell
    
    repeat with theTab in radioButtonList
      tell radio button theTab of front window
        perform action "AXPress"
      end tell
      set end of tabTargetList to getTabTarget() of me
    end repeat
    
  end tell
end tell

------------------------------------------------------------
--» HANDLERS
------------------------------------------------------------
on getTabTarget()
  tell application "Finder"
    return target of front window as alias
  end tell
end getTabTarget
------------------------------------------------------------

All it’s doing now is discovering the targets of the individual tabs.

But. From there you can select any tab you want and change that target.

It’s not exactly neat, but it would definitely be faster than doing things by hand.

-Chris

Although I haven't found a straight-forward way to do this with a script, I've attached a simple "found image" macro that's quick enough. It's not perfect but performs reasonably with anywhere between 2 and 10+ tabs.

I'm using El Capitan for the found image so you may need to adjust it for future / previous OS's

Move tabs.kmmacros (17.4 KB)

How about closing the tabs and re-opening them in the order you want? Not sure of the details, but I would think this is doable. Worth a shot, anyway.

2 posts were merged into an existing topic: How to Activate Finder Tabs with Shortcuts Cmd+1, Cmd+2

A post was merged into an existing topic: How to Activate Finder Tabs with Shortcuts Cmd+1, Cmd+2