Can't switch tabs/focus arbitrary tabs via AppleScript

RESOLVED FIXED

Status

--
enhancement
RESOLVED FIXED
10 years ago
9 years ago

People

(Reporter: alqahira, Assigned: alqahira)

Tracking

Details

(Whiteboard: [camino-2.0])

Attachments

(1 attachment)

We have no way of selecting an arbitrary tab via AppleScript.

Safari 3 and up use the obnoxious

tell {front window|window n} to set current tab to tab 1

which is better than nothing.  If OmniWeb has a way of doing this, it's even more obscure and I can't deduce it :P

Ideally, I'd expect

set current tab of browser window 1 to tab 2 of browser window 1

or possibly even

select tab 1 of browser window 1

to work.  We could do the "tell (browser window) n" thing to be compatible with Safari's syntax, but I'm not sure that's so important, particularly since I had to have the Internet tell me it existed.
"select" seems to be a core AppleScript command, but I can't figure out where it's defined or what it's expected to act upon; I don't see it in the AppleScript Language Guide.  We obviously don't want to redefine it if it's not intended to select single objects but is instead about selecting (highlighting) ranges or something else.
selectTabViewItem: is our Cocoa bit to do this?

Comment 3

9 years ago
For this you would want to use selectTabViewItemAtIndex:
Created attachment 404771 [details] [diff] [review]
fix

With some help from my friends Chris, Stuart, and Uncle Google, we can now switch tabs programmatically :)
Assignee: nobody → alqahira
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Attachment #404771 - Flags: review?(stuart.morgan+bugzilla)

Comment 5

9 years ago
Comment on attachment 404771 [details] [diff] [review]
fix

>+    [[NSScriptCommand currentCommand] setScriptErrorString:[NSString stringWithFormat:@"The tab to select must be in the same window.", nil]];

This should just be
  [[NSScriptCommand currentCommand] setScriptErrorString:@"The tab to select must be in the same window."];

r=smorgan with that change.
Attachment #404771 - Flags: superreview?(mikepinkerton)
Attachment #404771 - Flags: review?(stuart.morgan+bugzilla)
Attachment #404771 - Flags: review+
Comment on attachment 404771 [details] [diff] [review]
fix

sr=pink

+- (void)setCurrentTab:(BrowserWrapper *)newTabItemView;
+{
+  NSTabViewItem* newTabItem = [newTabItemView tab];

Use consistent spacing on Foo* vs. Foo *. Prefer Foo*.
Attachment #404771 - Flags: superreview?(mikepinkerton) → superreview+
Landed on CAMINO_2_0_BRANCH and cvs trunk with Stuart's change and with Foo * to match every other instance in the file ;-)

We can file a follow-up bug to make ScriptingSupport.mm's *s not make pink cry.
Status: ASSIGNED → RESOLVED
Last Resolved: 9 years ago
Resolution: --- → FIXED
Whiteboard: [camino-2.0]
You need to log in before you can comment on or make changes to this bug.