代码之家  ›  专栏  ›  技术社区  ›  Miki Tebeka

获取用于在OS X上启动应用程序包的文档的名称

  •  2
  • Miki Tebeka  · 技术社区  · 16 年前

    编写OS X捆绑应用程序(.app)时,如何获取导致应用程序启动的文档的名称?

    如何从MyApp中获取foo.abcd?(命令行参数仅包含进程id)。

    2 回复  |  直到 16 年前
        1
  •  1
  •   hbw    16 年前

    一般来说,这些都是通过 苹果事件 . 具体来说,您的应用程序将收到 打开文件 事件您将如何处理它取决于您正在编写的应用程序的类型。

    openDocumentWithContentsOfURL:display:error: 信息(或 openDocumentWithContentsOfFile:display: 对于Tiger之前的系统),以及 handle this accordingly .

    对于非基于文档的Cocoa应用程序,将向应用程序委托发送 application:openFiles: openTempFile: , openFiles: openFile:

    Here's the documentation 用于处理Cocoa中打开的Apple事件。

    kAEOpenDocuments AEInstallEventHandler() the documentation 更多细节。

        2
  •  1
  •   Miki Tebeka    16 年前

    idlelib/macosxSupport.py

    def doOpenFile(*args):
        for fn in args:
            flist.open(fn)
    
    # The command below is a hook in aquatk that is called whenever the app
    # receives a file open event. The callback can have multiple arguments,
    # one for every file that should be opened.
    root.createcommand("::tk::mac::OpenDocument", doOpenFile)
    

    support