Findwindow on a mac

Discussion in 'Mac Programming' started by xxarmoxx, Jun 29, 2007.

  1. macrumors newbie

    Joined:
    Jun 8, 2007
    #1
    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?
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    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.
     
  3. thread starter macrumors newbie

    Joined:
    Jun 8, 2007
    #3
    can you give me an example? Im not too sure what you are talking about. Thanks :cool:
     
  4. macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #4
    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];
    
    
     
  5. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    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.
     

Share This Page