I can open the Terminal tab using the following AppleScript:
tell application "Terminal"
set myTab to do script "exec sleep 1"
get myTab
end tell
It returns a string: tab 1 of window id 3263 of application "Terminal". This is great, I see the id 3263 window and tab number 1 (although I donβt know how to query myTab to get only these values).
In Cocoa ScriptingBridge, I can do:
SBApplication *terminal;
SBObject *tab;
terminal = [SBApplication applicationWithBundleIdentifier:@"com.apple.terminal"]
tab = [terminal doScript:@"exec sleep 1" in:nil]
How to get window id and tab number from tab object?
Edit 2009/4/27 - Why?
In answer to the question why I want to do this, I open the command in the terminal window (as indicated above) and return the tab object. However, I want to move / resize this window, so I need to access the object of the "window" tab.
Objective-C (, , Objective-C, Perl) , , NSAppleScript ScriptingBridge ( perl applescript 64- ). NSAppleScript, .
- TTY ( ) , , . , ( , !).
2009/4/30 -
has , NSAppleEventDescriptor API. NSAppleScript executeAndReturnError(). , NSAppleScript , ScriptingBridge.
ClassDump, SBObject, specifierDescription() qualifiedSpecifier(). "tab X of window id Y". Apple, .
( perl):
use Foundation;
NSBundle->bundleWithPath_('/System/Library/Frameworks/ScriptingBridge.framework')->load;
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";