• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Open a new terminal tab or window from a Cocoa app at a certain directory without using NSAppleScript?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Open a new terminal tab or window from a Cocoa app at a certain directory without using NSAppleScript?


  • Subject: Re: Open a new terminal tab or window from a Cocoa app at a certain directory without using NSAppleScript?
  • From: Andrew <email@hidden>
  • Date: Thu, 26 Jan 2012 11:22:54 -0700

Well, I figuredĀ it out for myself. Posting here in case anyone else
wants to do the same:

- (void)openTerminal:(id)sender
{
  TerminalApplication* termApp = [SBApplication
applicationWithBundleIdentifier:@"com.apple.terminal"];
  NSString *dir = // Get your directory here
  NSString *cmd = [NSString stringWithFormat:@"cd \"%@\"; clear",
dir]; // Assumes bash, which is okay for me, but maybe not others.

  TerminalWindow *window = nil;
  if (termApp.windows.count > 0)
  {
    // Use the first window:
    window = [termApp.windows objectAtIndex:0];
  }

  TerminalSettingsSet *settings = [termApp startupSettings];
  TerminalTab *newTab = [termApp doScript:cmd in:window];
  [newTab setCurrentSettings:settings];
  [newTab setSelected:YES];

  [termApp activate];
}

On Thu, Jan 26, 2012 at 11:02 AM, Andrew <email@hidden> wrote:
>
> Well, I found this:
> http://code.google.com/p/cdto/source/browse/plugins/terminal/CD2Terminal.m?spec=svn20c4d028f197a6810230ddff969de81c4b23876d&r=20c4d028f197a6810230ddff969de81c4b23876d
>
> And got the terminal opening in a new window at the path. So I now need to find how I can set the settings and have it open a new tab instead of window.
>
>
> On Thu, Jan 26, 2012 at 10:13 AM, Andrew <email@hidden> wrote:
>>
>> I would like to perform the same logic as the "New Terminal Tab at Folder" service in Finder in my Cocoa app. The only code I found via Google is all using AppleScript to open the Terminal.app, but nothing I found was a Cocoa interface besides 3rd party terminal apps (iTerm, iTerm2). Is there a better way than using NSAppleScript to do this?
>>
>> I do not see any core libraries for the terminal app, but perhaps I am just looking in the wrong location.
>>
>> If I were to use NSWorkspace, I tried using the "open" at the command line, but I am not able to:
>>
>> figure out how to open a new tab as opposed to a window
>> not have to run a program
>> it does not open the default terminal "theme"
>>
>> Thanks,
>> Andrew
>
>

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Open a new terminal tab or window from a Cocoa app at a certain directory without using NSAppleScript?
      • From: Jens Alfke <email@hidden>
References: 
 >Open a new terminal tab or window from a Cocoa app at a certain directory without using NSAppleScript? (From: Andrew <email@hidden>)
 >Re: Open a new terminal tab or window from a Cocoa app at a certain directory without using NSAppleScript? (From: Andrew <email@hidden>)

  • Prev by Date: Re: Open a new terminal tab or window from a Cocoa app at a certain directory without using NSAppleScript?
  • Next by Date: Re: Atta Boys, 4 bags-full
  • Previous by thread: Re: Open a new terminal tab or window from a Cocoa app at a certain directory without using NSAppleScript?
  • Next by thread: Re: Open a new terminal tab or window from a Cocoa app at a certain directory without using NSAppleScript?
  • Index(es):
    • Date
    • Thread