Comparing different 'the launching Cocoa app with parameters' methods

前端 未结 2 1541
攒了一身酷
攒了一身酷 2021-01-03 07:11

I found there are at least three ways to launch an app with Mac OS X from an application.

  1. NSTask. I can give parameters, but it seems that it\'s not for an Coc
相关标签:
2条回答
  • 2021-01-03 07:33

    In 10.6 and later, NSWorkspace has a method launchApplicationAtURL:options:configuration:error: that can be used to pass arguments to the app.

    There are also Launch Services functions such as LSOpenItemsWithRole.

    You could also send an AppleEvent to the Finder asking it to open something.

    EDIT TO ADD: "best" is subjective, but I'd say if you can use NSWorkspace, use it. If you can't, e.g., you need to pass command-line parameters and you need to support Leopard, then use Launch Services.

    0 讨论(0)
  • 2021-01-03 07:48

    By using Scripting Bridge, you can use the method activate to launch a cocoa app. See: Scripting Bridge.

    0 讨论(0)
提交回复
热议问题