Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 29, 2007, 04:11 PM   #1
xxarmoxx
macrumors newbie
 
Join Date: Jun 2007
Findwindow on a mac

With windows you can use the function findwindow() in user32.dll to find running windows. Is there a way to do that with a mac? I want to use java to find the running terminal window and when I click buttons on my java gui I want certain commands to be inserted to the terminal. How can I make this happen?
xxarmoxx is offline   0 Reply With Quote
Old Jun 29, 2007, 04:46 PM   #2
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Why would you want to use an actual Terminal window? You can just shell out and execute the commands you want.

If you really have to then I'd imagine you can shell out to AppleScript.
robbieduncan is offline   0 Reply With Quote
Old Jun 29, 2007, 05:50 PM   #3
xxarmoxx
Thread Starter
macrumors newbie
 
Join Date: Jun 2007
can you give me an example? Im not too sure what you are talking about. Thanks
xxarmoxx is offline   0 Reply With Quote
Old Jun 29, 2007, 09:54 PM   #4
Catfish_Man
macrumors 68030
 
Catfish_Man's Avatar
 
Join Date: Sep 2001
Location: Portland, OR
Send a message via AIM to Catfish_Man
Well, assuming you were asking for an example of running a shell program directly, rather than inserting stuff into a Terminal window (which is a terrible idea, in general)...
Code:
    NSTask *task = [[NSTask alloc] init];
    [task setLaunchPath: @"path to some shell command"];

    NSArray *arguments = [NSArray arrayWithObjects: @"argument 1", @"argument2", nil];
    [task setArguments: arguments];

    [task launch];
    [task waitUntilExit];
Catfish_Man is offline   0 Reply With Quote
Old Jun 30, 2007, 02:29 AM   #5
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Catfish_Man that is a lovely example. Unfortunately it's on Cocoa/Obj-C, not in Java!

In Java we'd use a method in the Runtime class to spawn a Proccess object. Using that we could communicate with the subprocess via buffered readers. You could simply spawn a shell (say Bash) and then pipe it commands and read the results.
robbieduncan is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
mac to windows and ten years later back to Mac, need some alternative app suggestions debudebu Mac Applications and Mac App Store 1 Apr 5, 2014 02:53 PM
Migration assistant (Mac - Mac). New mac has mutiple drives, can't pick the right one Daftones MacBook Pro 4 Aug 29, 2013 09:32 AM
Linux and mac shared Data partition. (paragon extFS-mac, ntfs-mac, ntfs-3G ?) HiDeHo OS X 10.8 Mountain Lion 15 Jul 17, 2013 05:09 PM
Samsung announced 24" Mac compatible touchscreen monitor. Does it work on Mac 10.8.4? Warrenn Mac Peripherals 7 Jul 12, 2013 10:34 PM

Forum Jump

All times are GMT -5. The time now is 04:23 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC