Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a sandboxed app to the login items

Tags:

I want my app to auto start if the user select the option. The methods I have been using is not allowed anymore in sandboxed apps.

I know I have to create a helper to achieve that? Is there a simple tutorial with sample code to active that?

I found this tutorial, but it does not work for me: http://www.delitestudio.com/2011/10/25/start-dockless-apps-at-login-with-app-sandbox-enabled/

It is a pretty standard thing to do, I don't understand why there is no example project available.

UPDATE:

I uploaded a sample project: http://ge.tt/6DntY4K/v/0?c

like image 991
Tibidabo Avatar asked Jul 02 '12 10:07

Tibidabo


2 Answers

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.

like image 139
Tim Avatar answered Oct 29 '22 19:10

Tim


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   .... 
like image 39
Homer Wang Avatar answered Oct 29 '22 19:10

Homer Wang