【问题标题】:Hide an application on launch when invoked using NSTask使用 NSTask 调用时在启动时隐藏应用程序
【发布时间】:2013-05-13 18:43:55
【问题描述】:

我正在使用 NSTask 启动一个应用程序,并使用 NSPipe 来获取它的标准输出和标准错误。我想在启动时隐藏它(GUI),因为该应用程序只是执行一些命令并退出。我不能使用 NSWorkspace,因为我需要 stdout/stderr。有谁知道实现这一目标的方法?

【问题讨论】:

  • 正在启动的应用程序是拥有代码的应用程序,还是您(或用户)购买并安装的其他应用程序?
  • 用户安装的其他应用程序。

标签: objective-c macos nstask


【解决方案1】:
/*
 *  TransformProcessType()
 *  
 *  Summary:
 *    Changes the 'type' of the process specified in the psn parameter.
 *     The type is specified in the transformState parameter.
 *  
 *  Discussion:
 *    Given a psn for an application, this call transforms that
 *    application into the given type.  Foreground applications have a
 *    menu bar and appear in the Dock.  Background applications do not
 *    appear in the Dock, do not have a menu bar ( and should not have

....

这就是我正在做的事情

【讨论】:

    【解决方案2】:

    NSRunningApplication 会给你一个代表应用程序的对象,如果你有它的进程 ID:+[NSRunningApplication runningApplicationWithProcessIdentifier:],你应该可以从 -[NSTask processIdentifier] 获得它。

    然后您可以将hide 发送到NSRunningApplication 实例。

    【讨论】:

    • 这确实有效,但它仅在应用程序 gui 完全加载并显示后才有效,因此在隐藏之前它会明显可见一秒。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多