• 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: Using Terminal within Cocoa App.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using Terminal within Cocoa App.


  • Subject: Re: Using Terminal within Cocoa App.
  • From: has <email@hidden>
  • Date: Wed, 16 Jan 2008 14:37:39 +0000

Caroline wrote:

I want to run some App by using Terminal script.


If you're wanting to run shell scripts in Terminal (as opposed to just executing them directly via NSTask), you need to send Terminal a 'do script' event. Example:

OSStatus DoTerminalScript(char *utf8Script) {
    /*
     * Run a shell script in Terminal.app.
     * (Terminal.app must be running first.)
     */
    char *bundleID = "com.apple.terminal";
    AppleEvent evt, res;
    AEDesc desc;
    OSStatus err;

// Build event
err = AEBuildAppleEvent(kAECoreSuite, kAEDoScript,
typeApplicationBundleID,
bundleID, strlen(bundleID),
kAutoGenerateReturnID,
kAnyTransactionID,
&evt, NULL,
"'----':utf8(@)", strlen(utf8Script), utf8Script);
if (err) return err;
// Send event and check for any Apple Event Manager errors
err = AESendMessage(&evt, &res, kAEWaitReply, kAEDefaultTimeout);
AEDisposeDesc(&evt);
if (err) return err;
// Check for any application errors
err = AEGetParamDesc(&res, keyErrorNumber, typeSInt32, &desc);
AEDisposeDesc(&res);
if (!err) {
AEGetDescData(&desc, &err, sizeof(err));
AEDisposeDesc(&desc);
} else if (err == errAEDescNotFound)
err = noErr;
return err;
}


To launch Terminal.app, use -[NSWorkspace launchApplication:], LSOpenApplication() or similar.


If you need to do anything more complex, I'd recommend using a high- level bridge such as objc-appscript <http://appscript.sourceforge.net/objc-appscript.html > or Leopard's Scripting Bridge.


HTH

has
--
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org

_______________________________________________

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: Using Terminal within Cocoa App.
      • From: "Bruce Johnson" <email@hidden>
  • Prev by Date: Distributed Objects - bycopy
  • Next by Date: Variable Variable?
  • Previous by thread: Re: Using Terminal within Cocoa App.
  • Next by thread: Re: Using Terminal within Cocoa App.
  • Index(es):
    • Date
    • Thread