且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何更改OS X应用程序包中的可执行文件

更新时间:2023-10-09 16:39:28

创建一个常规应用程序包,但是在其上设置 LSUIElement ,这样脚本应用程序的图标就不会被停放,并将Firefox 包含在包中。

这样做的一个简单方法是使用 参数选中设置
$ 1到应用程序的路径复选框,
所以你的脚本可以引用文件
在这个包里面。
检查在后台运行 - 这个设置
code> LSUIElement 给你。

  • 应用程序到
    资源文件夹,放下Firefox。

  • 将输出更改为无,以便您的日志
    消息进入系统

  • 在自定义图标上放置Firefox的图标文件(firefox.icns)。


  • 将App Name更改为Firefox。

    $ b

    对于类似下面的脚本:

  • / p>

     #!/ bin / sh 
    在前>& 2
    $ 1 /内容/资源/ Firefox.app/Contents/MacOS/firefox-bin
    在>& 2
    后回显

    你得到如下输出:

      4/8/09 1:16:33 PM [0x0-0x801801] .net.sabi .PlatypusScript [76610] 
    之前4/8/09 1:16:35 PM firefox-bin [76613]数据库加载时间:0.373( 717个对象)
    4/8/09 1:16:35 PM [0x0-0x801801] .net.sabi.PlatypusScript [76610]
    2009-04-08 13:16:35.699 firefox-bin [ 76613:10b]数据库加载时间:0.373(717对象)
    2009年8月8日下午1:16:57 [0x0-0x801801] .net.sabi.PlatypusScript [76610]

    如果您的用户以其他方式启动Firefox,例如使用URL处理程序和打开HTML文件,则需要使用本地应用程序,它可以将相应的Apple事件传递给Firefox,并将相应的URL和文件处理程序信息添加到Info.plist。 ( aemreceive 是一个方便的苹果事件接收的Python包装。)


    I would like to run a script before Firefox starts & after it quits. In Ubuntu I do this by creating a new shortcut that calls my function first, then calls the firefox command, then calls my last function. Since the firefox command blocks until the application quits, my last function is called immediately after the process ends.

    However, in OS X I cannot do this as nicely because I end up with two icons on the dock. One for my script turned into an application & another for the Firefox application. I would prefer to just have one dock icon & to not break Firefox updates.

    My current solution is to rename both MacOS/firefox{,-bin} to be prefixed with 'real-" and then name my shell script "firefox-bin". This works, but I am pretty sure that the next time firefox tries to update itself I am toast.

    I have tried changing the "CFBundleExecutable" property in the bundle's Info.plist file to be my script, but that doesn't work.

    Can anyone offer any other suggestions?

    Create a regular application bundle but set LSUIElement on it, so the script application's icon is hidden from the dock, and include Firefox inside the bundle.

    A simple way of doing this is with Platypus. Configure Platypus as follows:

    • Click "Parameters". Check the "Set $1 to path to application" checkbox, so your script can reference files inside the bundle.

    • Check "Runs in background"—this sets LSUIElement for you.

    • In the list of "Files and folders to be bundled with application into the Resources folder", drop Firefox.

    • Change Output to "None" so your log messages go to the system console.

    • Drop Firefox's icon file (firefox.icns) on the "Custom Icon" well.

    • Change "App Name" to Firefox.

    For a script that looks something like this:

    #!/bin/sh
    echo before >&2
    $1/Contents/Resources/Firefox.app/Contents/MacOS/firefox-bin
    echo after >&2
    

    you get output like:

    4/8/09 1:16:33 PM [0x0-0x801801].net.sabi.PlatypusScript[76610] before 
    4/8/09 1:16:35 PM firefox-bin[76613] Database load time: 0.373 (717 objects) 
    4/8/09 1:16:35 PM [0x0-0x801801].net.sabi.PlatypusScript[76610]
    2009-04-08 13:16:35.699 firefox-bin[76613:10b] Database load time: 0.373 (717 objects) 
    4/8/09 1:16:57 PM [0x0-0x801801].net.sabi.PlatypusScript[76610] after 
    

    If your users launch Firefox in other ways, such as with URL handlers and by opening HTML files, you'll instead need to use a native application, which can pass the appropriate Apple Events through to Firefox, and add the appropriate URL and file handler information to the Info.plist. (aemreceive is a convenient Python wrapper for Apple Event reception.)