添加应用OSX"登录项目"一个包装设备的安装脚本飞行后在 [英] Add app to OSX "Login Items" during a Package Maker installer postflight script

查看:151
本文介绍了添加应用OSX"登录项目"一个包装设备的安装脚本飞行后在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种方法来将应用程序添加到从中运行作为我的安装程序的一部分飞行后脚本登录项。它需要在10.5+工作。 preferably,它会在bash脚本工作。我的应用程序已经要求管理权限。

I need a way to add an application to the Login Items from a postflight script which is run as part of my installer. It needs to work on 10.5+. Preferably, it would work in a bash script. My application already requires administrative rights.

我发现这里的方法:的Mac OS登录项目与参数似乎是在正确的轨道(下面附带)上...但是,当我试图在命令行没有工作,我不知道如何使它为所有用户安装或者如果我需要添加逻辑来检查,如果它调用此code之前已经被添加到启动项。

The approach I found here: Mac OS Login Items with Arguments? seemed to be on the right track (included below)... but didn't work when I tried it on command line and I'm not sure how to make it install for All Users or if I need to add logic to check if it's already added to startup items before calling this code.

#!/bin/bash
/usr/bin/osascript -e "tell application \"System Events\" to make new login item with properties { path: \"$1\", hidden:false } at end"

我怀疑我还可以做些什么用的launchd。但是,我不知道哪种方法是跨版本兼容的最佳实践。

I suspect I could also do something with a launchd. But, I'm not sure which approach is the best practice for compatibility across versions.

注意:我不想用我的应用程序里面的一些目标c code以添加它。我需要的安装程序来添加它目前,我做的是启动应用程序的安装之后,然后添加它来登录使用LSSharedFileListRef在code项目......这种方法的例子可以在这里找到: 你如何让你的应用程序在登录时打开? 。究其原因,这是不正常的,我需要让我的应用程序通过命令行与苹果远程桌面安装时,在登录屏幕上。因此,应用程序需要不启动自动安装后。

NOTE: I do NOT want to add it using some objective-c code inside my app. I need the installer to add it. Currently, what I do is start the application after install which then Adds it to Login Items in code using the LSSharedFileListRef... Example of that approach can be found here: How do you make your App open at login?. The reason this is not ok is I need to make my application install with Apple Remote Desktop via command line, when on the login screen. So, the application needs to not start automatically after install.

推荐答案

下面的选项,我调查和试验:

Here's the options I investigated and experimented with:

这是我使用的方法。它很容易从一个bash文件做中加入下面一行到你的飞行后。

This is the method I used. It's very easy to do from a bash file by adding the following line to your postflight.

defaults write /Library/Preferences/loginwindow AutoLaunchedApplicationDictionary -array-add '{Path="/Applications/Your Application.app";}'

请注意:您甚至不必担心,如果你重新安装应用程序添加重复。在登录窗口过程删除重复时,它读取它们。

Note: You don't even have to worry about adding duplicates if you reinstall the application. The loginwindow process removes duplicates when it reads them.

我测试的10.5,10.6和10.7

@noa说,这不会对山狮(10.8)工作,没有亲自证实。

I tested this on 10.5, 10.6, and 10.7
@noa says this doesn't work on mountain lion (10.8), Haven't personally confirmed.

使用启动代理的唯一后果是:

The unique ramifications of using a Launch Agent are:


  1. 您的应用程序不会出现在登录项目列表,因此
    用户真的知道他们在做什么,以摆脱它

  2. 用户无法不运行结束你的应用程序:
    launchctl卸载/Library/LaunchAgents/com.your.package.plist

下面是一些code你可以使用你的bash的文件中创建展开剂:

Here's some code you could use to create the launch agent in your bash file:

cat > /Library/LaunchAgents/com.your.application.agent.plist << EOT
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.your.application.agent</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Applications/Your Application.app/Contents/MacOS/Your Application</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>
EOT

选项3:编译的OBJ-C code二进制

我从来没有真正完成了这种方法。显然,这是Novell公司所采用的方法。从本质上讲,你会做调用从该解决方案中引用的库为基础的应用程序:
你如何让你的应用程序在登录时打开?

如果你想让它在你需要使用的AppleScript虎的工作没有尝试这不过根据这个帖子..?我无法证实或否认,但认为这种联系可能是相关的。
<一href=\"http://stackoverflow.com/questions/2702961/editing-mac-os-x-login-items-in-objective-c-through-applescript\">Editing通过AppleScript的在Objective-C的Mac OS X登录项目

Didn't try this but according to this post if you want it to work on tiger you need to use AppleScript..? I can't confirm or deny that but thought this link might be relevant. Editing Mac OS X login items in Objective-C through AppleScript

这篇关于添加应用OSX&QUOT;登录项目&QUOT;一个包装设备的安装脚本飞行后在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆