NSTask's launchedTaskWithLaunchPath:arguments: versus NSWorkspace's launchApplication:

  • Hi,

    We have an application that needs to launch another application from
    within itself. Now, we could either do this using NSTask's
    "launchedTaskWithLaunchPath:arguments:" or getting the shared
    workspace from NSWorkspace and send "launchApplication:" to it.

    Now the problem is that we want the newly launched application to (1)
    get focus (e.g. we want it to be the active application from now on)
    and (2) to be able to receive the regular command line arguments we
    send it. The two above mentioned operations either accomplishes 1
    (NSWorkspace) or 2 (NSTask) but not both simultaneously.

    Does anyone know how I could solve this?

    Thanks in advance, and merry christmas.
    Mattias
  • Le 20 déc. 07 à 18:22, Mattias Arrelid a écrit :

    > Hi,
    >
    > We have an application that needs to launch another application from
    > within itself. Now, we could either do this using NSTask's
    > "launchedTaskWithLaunchPath:arguments:" or getting the shared
    > workspace from NSWorkspace and send "launchApplication:" to it.
    >
    > Now the problem is that we want the newly launched application to
    > (1) get focus (e.g. we want it to be the active application from now
    > on) and (2) to be able to receive the regular command line arguments
    > we send it. The two above mentioned operations either accomplishes 1
    > (NSWorkspace) or 2 (NSTask) but not both simultaneously.
    >
    > Does anyone know how I could solve this?
    >
    > Thanks in advance, and merry christmas.
    > Mattias

    I don't know a proper Cocoa way to do it but i can give you a
    workaround.

    NSTask *task = [NSTask ......];
    pid_t pid = [task processIdentifier];
    ProcessSerialNumber psn;
    if (noErr == GetProcessForPID(pid, &psn)) {
    SetFrontProcess(&psn);
    }

    The LSOpenApplication() function may also works, but the doc says that
    argv is ignored on 10.4, so use it only if you want to target Leopard.
    Merry christmas too
  • The NSDistributedNotificationCenter class provides a way to send
    notifications to objects in other tasks.

    Merry X'mas~

    On Dec 21, 2007, at 1:50 AM, Jean-Daniel Dupas wrote:

    >
    > Le 20 déc. 07 à 18:22, Mattias Arrelid a écrit :
    >
    >> Hi,
    >>
    >> We have an application that needs to launch another application
    >> from within itself. Now, we could either do this using NSTask's
    >> "launchedTaskWithLaunchPath:arguments:" or getting the shared
    >> workspace from NSWorkspace and send "launchApplication:" to it.
    >>
    >> Now the problem is that we want the newly launched application to
    >> (1) get focus (e.g. we want it to be the active application from
    >> now on) and (2) to be able to receive the regular command line
    >> arguments we send it. The two above mentioned operations either
    >> accomplishes 1 (NSWorkspace) or 2 (NSTask) but not both
    >> simultaneously.
    >>
    >> Does anyone know how I could solve this?
    >>
    >> Thanks in advance, and merry christmas.
    >> Mattias
    >
    > I don't know a proper Cocoa way to do it but i can give you a
    > workaround.
    >
    > NSTask *task = [NSTask ......];
    > pid_t pid = [task processIdentifier];
    > ProcessSerialNumber psn;
    > if (noErr == GetProcessForPID(pid, &psn)) {
    > SetFrontProcess(&psn);
    > }
    >
    > The LSOpenApplication() function may also works, but the doc says
    > that argv is ignored on 10.4, so use it only if you want to target
    > Leopard.
    > Merry christmas too
    >
  • On 12/21/07, Constantine <qliu...> wrote:
    >
    >
    >
    > The NSDistributedNotificationCenter class provides a way to send
    > notifications to objects in other tasks.
    > Merry X'mas~

    Hm, maybe that's an idea. If I launch the new application, and from
    within that send a distributed notification once everything is loaded
    - and at the same time wait in the original application to recieve the
    distributed notification - then I should be able to  call
    SetFrontProcess() as Jean-Daniel suggested.

    Thanks for your input!

    > On Dec 21, 2007, at 1:50 AM, Jean-Daniel Dupas wrote:
    >
    >
    > Le 20 déc. 07 à 18:22, Mattias Arrelid a écrit :
    >
    >
    > Hi,
    >
    > We have an application that needs to launch another application from within
    > itself. Now, we could either do this using NSTask's
    > "launchedTaskWithLaunchPath:arguments:" or getting the
    > shared workspace from NSWorkspace and send "launchApplication:" to it.
    >
    > Now the problem is that we want the newly launched application to (1) get
    > focus (e.g. we want it to be the active application from now on) and (2) to
    > be able to receive the regular command line arguments we send it. The two
    > above mentioned operations either accomplishes 1 (NSWorkspace) or 2 (NSTask)
    > but not both simultaneously.
    >
    > Does anyone know how I could solve this?
    >
    > Thanks in advance, and merry christmas.
    > Mattias
    >
    > I don't know a proper Cocoa way to do it but i can give you a workaround.
    >
    > NSTask *task = [NSTask ......];
    > pid_t pid = [task processIdentifier];
    > ProcessSerialNumber psn;
    > if (noErr == GetProcessForPID(pid, &psn)) {
    > SetFrontProcess(&psn);
    > }
    >
    > The LSOpenApplication() function may also works, but the doc says that argv
    > is ignored on 10.4, so use it only if you want to target Leopard.
    > Merry christmas too
previous month december 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Go to today