How to add a sandboxed app to the login items

橙三吉。 提交于 2019-12-02 18:14:36

You should succeed by using this (disclaimer: my) tutorial, sample project included.

Update: I've now tested the sample project you've uploaded: It works just fine with me, without any modifications, and launch at login succeeds. The only trick is that the AutoStart.app file has to be placed in the /Applications or ~/Applications folder to be launched successfully at login. This is necessary regardless of whether the app is sandboxed or not. However, there's no official documentation on this, I'm afraid.

Homer Wang

I've just re-done about 100 trial on Tim's tutorial. Finally I made it work. Although I swear it worked when I first time tried it. In my situation is when I switch "Launch at login" to On, I can only see the helper app launched for just one second right after login. Then it was gone. Manually start the app, I saw the switch was turned off.

Here was what I found:

  1. my bundle identifier was already in the list of NSArray *running = [[NSWorkspace sharedWorkspace] runningApplications]
  2. the status of the NSRunningApplication *app (bundle name equal to my app) is: [app isActive] == NO, [app isHidden] == NO, [app isTerminated] = NO

So I made some modification to the code like:

BOOL alreadyRunning = NO;
BOOL isActive = NO; // my modification
NSArray *running = [[NSWorkspace sharedWorkspace] runningApplications];
for (NSRunningApplication *app in running) {

    if ([[app bundleIdentifier] isEqualToString:@"com.mybundleidentifier"]) {
        alreadyRunning = YES;
        isActive = [app isActive]; // my modification
    }
}

if (!alreadyRunning || !isActive) { // my modification
  ....
Remear

You could try using the Service Management Framework

http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLoginItems.html#//apple_ref/doc/uid/10000172i-SW5-SW1

As referenced from http://developer.apple.com/library/mac/#documentation/Security/Conceptual/AppSandboxDesignGuide/DesigningYourSandbox/DesigningYourSandbox.html ...

To create a login item for your sandboxed app, use the SMLoginItemSetEnabled function (declared in ServiceManagement/SMLoginItem.h) as described in Adding Login Items Using the Service Management Framework in Daemons and Services Programming Guide.

(With App Sandbox, you cannot create a login item using functions in the LSSharedFileList.h header file. For example, you cannot use the function LSSharedFileListInsertItemURL. Nor can you manipulate the state of launch services, such as by using the function LSRegisterURL).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!