MacOS – In AppleScript can you create a window tab without using keystroke

applescriptfindermacos

In AppleScript you can create a finder window with:

tell application "Finder"
    activate
    set newWindow to make new Finder window
end tell

after setting the target if you want to create a new tab I'm aware of:

tell application "System Events"
    keystroke "t" using command down
end tell

per searching through older questions and from Google. In AppleScript is there another way to create tabs without having to use:

keystroke "t" using command down

and if a window is created with four tabs is there a way to change what tab the window is active in? For example:

tab 1
tab 2
tab 3
tab 4

Looping through the tabs with a repeat and keystroke final tab would be tab 4 but I'm not sure how to tell the finder window that the frontmost tab should be tab 2 and I dont want to change the sequence the tabs are created meaning, I dont want:

tab 1
tab 3
tab 4
tab 2

or is there an efficient way to parse what tabs are open in that particular tab? Can this be done?

Best Answer

I can say until 10.9 this isn't possible because the property of tab isn't implemented into applescript. After 10.9... I don't know but you can check it by yourself like this: Open 1 Finder Window with two or more tabs, then:

tell application "Finder"
properties of Finder window 1
end tell

...now if you can find something in the result that speaks about tab, then you can use this property to work on tabs. Alternatively just open the Applescript Finder Library and search for tab. It would show you if there is a property.

Also...

tell application "System Events"
keystroke "t" using command down
end tell

wouldn't be necessary if property tabs would be implemented into Applescript.