Add app at login items - MAS

  1. 2 years ago

    Christoph D

    1 Jun 2017 Pre-Release Testers, Xojo Pro

    How can I add/remove my app to the login items so my apps auto launch when the systems boot.
    I know a way to this with Applescript but it needs to work when sandboxed and for the MAS.

    MBSplugins or declares are welcome. :)

  2. Edited 2 years ago

    Lets clarify... You want the app to launch on Login or when the machine boots? Which is it?

  3. Christian S

    1 Jun 2017 Pre-Release Testers, Xojo Pro, XDC Speakers Germany

    I think you can add login items using LSSharedFileListMBS class.

    http://monkeybreadsoftware.net/class-lssharedfilelistmbs.shtml

  4. Christian S

    1 Jun 2017 Pre-Release Testers, Xojo Pro, XDC Speakers Germany

    e.g. like this:

    // Add iPhoto to launch items
    
    // pick app
    dim app as FolderItem = SpecialFolder.Applications.Child("iPhoto.app")
    
    // get list object
    dim l as new LSSharedFileListMBS(LSSharedFileListMBS.kSessionLoginItems)
    
    // insert file
    dim item as LSSharedFileListItemMBS = l.InsertFile(l.kLSSharedFileListItemBeforeFirst, "Launch iPhoto", nil, app)
    
    // check error
    if l.Lasterror = 0 then
      MsgBox "OK"
    else
      MsgBox "Failed: "+str(l.Lasterror)
    end if
  5. Michel B

    1 Jun 2017 Pre-Release Testers RubberViews.com

    @Christoph Dnbsp;Vocht How can I add/remove my app to the login items so my apps auto launch when the systems boot.
    I know a way to this with Applescript but it needs to work when sandboxed and for the MAS.

    MBSplugins or declares are welcome. :)

    Remember that thread where Valdemar de Susa posted the how to of his helper for you ?
    https://forum.xojo.com/14457-launchagents-howto/1

    I have used his helper for several years for MAS apps.

  6. Christoph D

    1 Jun 2017 Pre-Release Testers, Xojo Pro

    LSSharedFileList seems to be deprecated.
    I don't want to use launchdaemon or launchagent because they are processed very late in the system boot sequence. The login items is what I need.

    Do I understand it correctly you need a helper app for this? Why not just launch the main app? This is how I do it now. Is this really needed for the MAS?

  7. Christian S

    1 Jun 2017 Pre-Release Testers, Xojo Pro, XDC Speakers Germany

    Oh, than please ask Apple for what is replacement in 10.12.

  8. Jared F

    1 Jun 2017 Pre-Release Testers, Xojo Pro Milwaukee, WI

    Yes, I believe that you need a helper app for sandboxed MAS applications.
    Your application isn't allowed to change user preferences (login items) in a sandboxed environment.

  9. Christoph D

    1 Jun 2017 Pre-Release Testers, Xojo Pro

    Tried for two hours with the Valdemar method but I keep getting the same errors as Oliver O gets.
    https://forum.xojo.com/14457-launchagents-howto/1

    @Oliver O: did you resolve this issue?
    Anyone else found a working version that works with 10.12 ?

  10. Michel B

    1 Jun 2017 Pre-Release Testers RubberViews.com

    I just tested my own Fonts Manager which has worked flawlessly until now. It appears the launch at startup feature based on VDSC no longer works. No crash, but the helper does not seem to start.

    For the time being, I am considering instructing the user how to right click the dock icon and select the option "Open at login".

  11. Beatrix W

    1 Jun 2017 Pre-Release Testers Europe (Germany)

    I've been using the code from Valdemar for a while. For most users it worked for some it didn't. Had to change to use a file in the LoginItems folder. This works reliably but the code is a bit more complicated. My app isn't sandboxed.

  12. Sam R

    1 Jun 2017 Pre-Release Testers, Xojo Pro Hengchun, Pingtung, Taiwan
    Edited 2 years ago

    I've just confirmed that Backup To Go works on Sierra; however I haven't updated it for a few years and it's no longer available (due to lack of interest).

    Feel free to give it a try: download the helper from the link below.
    http://www.ohanaware.com/xojo/LaunchHelper.zip

    It needs to be placed in ".app/Contents/Library/loginItems/" (as pictured below).
    -image-

    The plist of the helper needs to be modified in two places:
    1. It needs to have a UNIQUE bundle identifier, this can be your main application identifier with ".launchHelper" on the end.
    2. "mainAppBundleID" needs to be modified to include the bundle ID of your application.
    -image-

    Xojo code:
    Now this code won't be able to be dropped directly into your application because of it's dependancies, however the main declare still works "SMLoginItemSetEnabled". It's worth noting that I couldn't find a way to tell if it was active or not, hence why this code stores it in the preferences. Also what seems important is that the application must be in the Applications folder.

    When testing on my Sierra machine, all of the Apple things appear first, then the apps that were open before and finally a couple of a seconds later Backup To Go launches.

    #if TargetMacOS then
      declare function SMLoginItemSetEnabled lib "ServiceManagement" ( identifier as CFStringRef, value as boolean ) as boolean
      
      Dim newValue as boolean = not xPlatPreferences.lookup( kLaunchonloginIdentifier, false )
      
      Dim valueWasSet as boolean
      if debugBuild or left( app.executableFile.nativePath, 14 ) = "/Applications/" then
        valueWasSet = SmLoginItemSetEnabled( "com.ohanaware.backupToGoHelper", newValue )
      end if
      
      if valueWasSet = false then
        // - It failed.
        Dim errorMessage as string
        if not debugBuild and left( app.executableFile.nativePath, 14 ) <> "/Applications/" then
          errorMessage = appkit2015.localizedAppName + " needs to be in the Applications folder in order to launch on login."
          
        elseif newValue = true then
          errorMessage = kWasUnableToRegisterTheLoginItem
          
        else
          errorMessage = kCouldntUnregisterTheLoginItem
        end if
        
        Dim md as new messageDialog
        md.message = kFailedToAlterTheLaunchOnLoginStatus
        md.explanation = errorMessage
        
        call md.showModalWithin( self )
        
        newValue = not newValue
        
      else
        xPLatPreferences.value( kLaunchonloginIdentifier ) = newValue
        
      end if
      
      if xPlatPReferences.lookup( kLaunchonloginIdentifier, false ) then
        me.setIcon 0, retinaKit.imageNamed( retinaKit.imageName.statusAvailable )
      else
        me.setIcon 0, retinaKit.imageNamed( retinaKit.imageName.statusNone )
      end if
      
    #endif

    Hope that this helps.

  13. Christoph D

    2 Jun 2017 Pre-Release Testers, Xojo Pro

    Thank you Sam ! Will try this later today. Kudos

  14. Christian S

    2 Jun 2017 Pre-Release Testers, Xojo Pro, XDC Speakers Germany

    Please also check ServiceManagementModuleMBS here:

    http://monkeybreadsoftware.net/module-servicemanagementmodulembs.shtml

    RegisterHelperApp may also help as well as LoginItems functions.

  15. Sam R

    11 Jul 2017 Pre-Release Testers, Xojo Pro Hengchun, Pingtung, Taiwan

    One last thing is to disable "Inheritance" in the capabilities pane of App Wrapper, the Launch Helper won't launch otherwise.

  16. Christoph D

    12 Jul 2017 Pre-Release Testers, Xojo Pro
    Edited 2 years ago

    Another tip: Make sure your app is only present ones !! If the user has two (or more) versions of your app installed in different places, it will not work. It took me a while before finding out why it sometimes didn't work. The created debug versions by Xojo did trigger this issue.

    BTW the reason is that the login items are linked with the apps Bundle ID and it apparently confuses things.

  17. 4 weeks ago

    Scott C

    Dec 26 Aurora, IL

    So, I am resurrecting this thread for a problem I have encountered that I think is related.

    I have given this a try, both with the helper app provided by Sam Rowlands as well as one I built on my own and it appears to work as I would expect.

    However, I am unable to get App Wrapper to wrap the built applications correctly. When I try to wrap the application, App Wrapper gives me an error message indicating there are "Critical issues that need fixing". Those issues are:

    Gate Keeper 1 Invalid Resource Directory (directory Or Signature Have Been Modified)
    Code sign diagnosis (followed by a whole list of "validated" and "prepared" statements that look like they have something to do with a bunch of MBS plugins (all of which are used in my application).

    These errors did not occur until I added the helper app to my application's bundle with a CopyFilesTo build step. The helper app is located in .app/Library/LoginItems as I think it is supposed to.

    Any ideas?

  18. Sam R

    Dec 27 Pre-Release Testers, Xojo Pro Hengchun, Pingtung, Taiwan
    Edited 4 weeks ago

    @Scott C Gate Keeper 1 Invalid Resource Directory (directory Or Signature Have Been Modified)
    Code sign diagnosis (followed by a whole list of "validated" and "prepared" statements that look like they have something to do with a bunch of MBS plugins (all of which are used in my application).

    First thing to to try is to restart your Mac. I'm not kidding either, some people have terrible trouble code signing, and it's resolved when their computer is restarted (my guess is the Code Signing libraries cache some kind of information and it gets corrupted or whatever).

    Second thing to try is to send me the log (via e-mail support) and I'll take a look at it and hopefully the code signing API returned an error that's useful (it doesn't always).

    @Scott Crick These errors did not occur until I added the helper app to my application's bundle with a CopyFilesTo build step. The helper app is located in .app/Library/LoginItems as I think it is supposed to.

    This is occurring BEFORE the application gets sent to App Wrapper for code signing?

  19. Scott C

    Dec 27 Aurora, IL

    @Sam R First thing to to try is to restart your Mac. I'm not kidding either, some people have terrible trouble code signing, and it's resolved when their computer is restarted (my guess is the Code Signing libraries cache some kind of information and it gets corrupted or whatever).

    Yes, the computer has been restarted since my last post and the same errors are happening.

    @Sam R Second thing to try is to send me the log (via e-mail support) and I'll take a look at it and hopefully the code signing API returned an error that's useful (it doesn't always).

    Done. I thank you for any assistance you could provide.

    @Sam R This is occurring BEFORE the application gets sent to App Wrapper for code signing?

    Correct. The helper application is being added via a CopyFilesTo build step that occurs before the App Wrapper build script executes.

or Sign Up to reply!