As the title says I have an apple script that does:
in tab 2 of front window
Which used to work fine but since the High Sierra upgrade returns:
Terminal got an error: Can’t get tab 2 of window 1. (-1728)
Which corresponds to errAENoSuchObject
I can't find any documentation around this having changed - is this a bug? Is there a new or better way to do this?
The object hierarchy has changed slightly. Each tab is referenced in AppleScript as tab 1 belonging to a unique parent window object.
So, previously, if there were three tabs open in a single window, we could refer to them as tab 1, tab 2, and tab 3 of window 1. Now, we have tab 1 of window 1, tab 1 of window 2, and tab 1 of window 3.
I’ve found the most convenient and reliable way to target a specific tab is to identify the window object that contains the tab object with a specific tty property value. I use a command that looks something like this:
tell application "Terminal"
get the id of the first window ¬
whose first tab's tty contains "003"
set w to result
close window id w
end tell
If you want to get a slightly clearer picture of things, run this:
tell application “Terminal” to ¬
get every tab of every window
and this:
tell application “Terminal” to ¬
get properties of every window
and this:
tell application “Terminal” to ¬
get properties of tab 1 of every window
If your script's purpose is to open tabs and run a script in each one, and not to navigate between specific tabs, you can easily modify your script to do script in selected tab of front window
after opening a new tab, as the new tab is always automatically selected. This is my modified script:
tell application "Terminal"
activate
do script "YOUR SCRIPT 1" in tab 1 of front window
my makeTab()
do script "YOUR SCRIPT 2" in selected tab of front window
my makeTab()
do script "YOUR SCRIPT 3" in selected tab of front window
end tell
on makeTab()
tell application "System Events" to keystroke "t" using {command down}
delay 0.2
end makeTab
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With