Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 761091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:47:48+00:00 2026-05-14T15:47:48+00:00

I can open a Terminal tab using the following AppleScript: tell application Terminal set

  • 0

I can open a Terminal tab using the following AppleScript:

tell application "Terminal"
    set myTab to do script "exec sleep 1"
    get myTab
end tell

This returns a string like: tab 1 of window id 3263 of application "Terminal". This is great, I can see the window id 3263 and tab number 1 (although I don’t know how to query myTab to get only these values).

In the Cocoa ScriptingBridge, I can do:

SBApplication  *terminal;
SBObject       *tab;

terminal = [SBApplication applicationWithBundleIdentifier:@"com.apple.terminal"]
tab = [terminal doScript:@"exec sleep 1" in:nil]

How do I get the window id and tab number from the tab object?


Edit 2009/4/27 – Why?

In answer to why I want to do this – I am opening a command in a Terminal window (as above), and am getting back the tab object. However I want to move/resize this window, so I need to get access to the tab’s “window” object.

I am using Objective-C (well actually, Objective-C bridged from Perl), and want to stick to standard OS components, so I believe I only have the NSAppleScript and ScriptingBridge frameworks to play with (all the perl applescript modules broke with 64bit carbon removal). I would try NSAppleScript, but processing the returned values seems to be a black-art.

My current solution is to get the TTY of the tab object (guaranteed unique) and enumerate every tab of every window until I find the window containing the tab. I assumed that this couldn’t be the best way (it sure ain’t fast!).


Edit 2009/4/30 – Solution

Based on the suggestions of “has” below, I braved the NSAppleEventDescriptor API. Initially, I was only able to get to this with NSAppleScript’s executeAndReturnError() call. However I found that NSAppleScript was much, much slower than ScriptingBridge.

After using ClassDump to extract some more SBObject calls, I found the undocumented specifierDescription() and qualifiedSpecifier() calls. The former gives me the nice “tab X of window id Y” string. The latter returns the apple event descriptor, which I can then decode.

My final code (in perl) is:

use Foundation;

NSBundle->bundleWithPath_('/System/Library/Frameworks/ScriptingBridge.framework')->load;

# Create an OSType (bid endian long) from a string
sub OSType ($) { return unpack('N', $_[0]) }

my $terminal = SBApplication->applicationWithBundleIdentifier_("com.apple.terminal");

my $tab         = $terminal->doScript_in_("exec sleep 1", undef);
my $tab_ev_desc = $tab->qualifiedSpecifier;
my $tab_id      = $tab_ev_desc->descriptorForKeyword_(OSType 'seld')->int32Value;
my $win_ev_desc = $tab_ev_desc->descriptorForKeyword_(OSType 'from');
my $window_id   = $win_ev_desc->descriptorForKeyword_(OSType 'seld')->int32Value;

print "Window:$window_id Tab:$tab_id\n";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:47:49+00:00Added an answer on May 14, 2026 at 3:47 pm

    Technically you can’t; a better question is why do want to?

    (Well, okay, you could if you use the Apple Event Manager API or objc-appscript, both of which can give you a raw AEDesc/NSAppleEventDescriptor which you can recursively pull apart yourself. Or you might poke around in SB to see if there’s an undocumented API to get at the underlying AEDesc, but caveat emptor, of course. Alternatively, there may be a better way to achieve your actual goal without resorting to hackery, but you’d need to provide more information.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can we open a new terminal tab or window from the existing terminal using
How can I redirect my Python script output to one of the open terminal
Whenever I open a new tab in Terminal using Cmd + T , it
If I have several OS-X Terminal.app windows open, how can I move one Terminal
I can open Terminal and write mono example.exe, but I want to double click
How can I open a symlink without the terminal window popping up? Moreover, when
When I open a terminal running bash and type the following: cat\nfoo\n^Decho bar\n (where
I'm using Ubuntu 9.04 x64 and when I write: gnome-terminal --tab At the terminal,
Using Terminal.app on OS X 10.5, often you see the commands get garbled when
VIM seems integrated to the terminal. Can I open a remote file from the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.