Skip to content

The Eclectic Light Company

Macs, painting, and more
Main navigation
  • Downloads
  • M1 & M2 Macs
  • Mac Problems
  • Mac articles
  • Art
  • Macs
  • Painting
hoakley September 16, 2021 Macs, Technology

How to run an app or tool at startup

There are four popular ways of getting software to run whenever your Mac starts up, depending on whether it’s installed as a Login Item, or as a LaunchAgent or LaunchDaemon. This article looks at the differences between these mechanisms, so that you can decide which to use in each case, understand what can go wrong with them, and how to fix them.

Leave it running at shutdown

The simplest way to have an an app opened for you when you next start up is just to leave the app running when you shut down or restart. This does, of course, rely on you remembering to check that the app is running beforehand.

Add it from the Dock

There’s a quick and easy way to add apps which are already in the Dock to the Login Items list (discussed below): click and hold on their icon in the Dock until its menu pops up. In that, select Options, then the Open at Login command.

launchd

launchd is a generally reliable way for a user to set an app or tool to run at startup. As I explained earlier this week, creating an appropriate Property List in one of the LaunchAgents or LaunchDaemons folders in /Library will ensure it’s run before you log in, which probably isn’t what you intend. Instead, you’ll more likely want to install yours in ~/Library/LaunchAgents instead, so that it’s launched once you have logged in.

Setting the RunAtLoad key to true tells launchd to run the service or app then. To launch an app, set the ProgramArguments key to load the executable code within the app bundle, for example at AppName.app/Contents/MacOS/AppName. Remember that anything with a GUI must be a LaunchAgent.

Login Items

These are controlled quite differently, through LaunchServices rather than launchd, which runs later following startup. You can set any app, service, or other executable code to run at startup by adding the item to the list of Login Items in the Users & Groups pane in System Preferences.

loginitems

Once added, LaunchServices puts them into its list of apps to launch at startup, which in Sierra and earlier used to be located in ~/Library/Preferences/com.apple.loginitems.plist. Since High Sierra, that has moved, changed its extension, and the file structure, to ~/Library/Application Support/com.apple.backgroundtaskmanagementagent/backgrounditems.btm

That file isn’t intended to be maintained directly by the user. The new format is opaque: although a Property List, it is now a keyed archive containing objects which are referenced by UUID, and unsuitable for manual editing.

In addition to using the Dock menu or the Users & Preferences pane, you can add and remove Login Items using a scripting language; for example, in AppleScript
tell application "System Events" to make login item at end with properties {path:"/Applications/MyApp.app", hidden:false}
adds MyApp.app as a Login Item,
tell application "System Events" to get the name of every login item
lists all Login Items, and
tell application "System Events" to delete login item "name"
removes the named Login Item from the current list.

Login Items are better suited to apps of any size which have significant user interfaces, and anything which a user wants to control easily. Many apps, such as menu bar or ‘Status Bar’ apps, offer the user the option of installing them as a Login Item. Unfortunately, particularly when this is done for an app provided through the App Store, this turns out to be a complex development task which requires a helper app.

Sorting out LaunchServices problems isn’t easy. If you’re seeing weird things going on with your Login Items list, one possible solution is to start from scratch by trashing the current file, restarting, and setting up your Login Items again. Note that in some versions of macOS, until there is at least one Login Item, the settings file may not even exist.

Share this:

  • Twitter
  • Facebook
  • Reddit
  • Pinterest
  • Email
  • Print

Like this:

Like Loading...

Related

Posted in Macs, Technology and tagged AppleScript, LaunchAgents, launchd, LaunchDaemons, LaunchServices, Login Item, property list, startup, Users & Groups. Bookmark the permalink.

19Comments

Add yours
  1. 1
    Michele Galvagno on September 16, 2021 at 6:42 am

    Great article! What exactly does the “Hide” checkbox do? Simply launches the app without it being shown onscreen or in the menubar/Dock?

    Michele Galvagno

    LikeLiked by 2 people

    • 2
      hoakley on September 16, 2021 at 11:20 am

      Thank you.
      Yes, all that checkbox does is launch it silently. It’s ideal where there’s no user interaction to be done.
      Howard.

      LikeLiked by 2 people

      • 3
        Dakotamoons on September 16, 2021 at 2:57 pm

        Ideally checking the “hide” box on login items “should” hide that items from displaying, but to be honest I get almost arbitrary results with that checkbox. Such as, even when the “hide” box is checked the app or share still appears on my display. No big deal, just a little frustration I thought I’d make mention of. Am I the only one?

        LikeLiked by 1 person

        • 4
          hoakley on September 16, 2021 at 5:57 pm

          Thank you. I suspect if it’s an app with a GUI, that won’t suppress that. It’s mainly intended for otherwise faceless helper apps.
          Howard.

          LikeLike

  2. 5
    Old Coot on September 16, 2021 at 10:28 am

    Is there an app that one can use to launch apps that run first since they are needed before most anything else. Like a VPN app that can connect as soon as we see the WiFi icon appear and connected?

    LikeLiked by 2 people

    • 6
      hoakley on September 16, 2021 at 11:24 am

      VPN apps can’t work like that. What you see as an app is only the control and installer. They need to install some form of extension to be able to work, and it’s that which is loaded by the system during startup. In older times, this would probably have been a kernel extension, but these days it’s the new userland version.
      Howard.

      LikeLiked by 1 person

  3. 7
    Gideon on September 16, 2021 at 12:54 pm

    If one installs and launches the Spotify app it will automatically launch upon login.
    However the preference to disable auto launch is only accessible through the programs own preferences, which are only available if you have logged into a Spotify account. In the case you don’t have a Spotify account, it is therefore not possible to deactivate auto launch.
    I’ve checked all the locations you covered but didn’t find an entry that executes the Spotify app.
    There seems to be another method to launch an app that Spotify is using. I’m curious if anyone has a clue or hint – thanks.

    LikeLiked by 1 person

    • 8
      hoakley on September 16, 2021 at 5:55 pm

      Thank you.
      I’ve taken a look in the app and uses the LoginList approach, although it might keep its helper app to do that in its app bundle. Have you tried using AppleScript to see if it appears in the LoginList list? You may then be able to remove using AppleScript. The good thing is that removing the app should also prevent this.
      Howard.

      LikeLike

      • 9
        Samuel Herschbein on September 17, 2021 at 9:17 am

        I also scoured macOS for how Spotify auto-launches and didn’t figure it out. I’ve checked all the usual suspects. I gave EasyFind Full Disk Access to search the whole drive (including invisibles) for any files with “potify”. Nothing showed up.

        I made an AppleScript to list the Login Items, it’s not there (nor is it in the System Preferences > Users & Groups > Login items).

        IMHO what Spotify is doing is unconscionable. Rather than using methods familiar to users and Mac admins, they’ve chosen to use some trick that mere mortals aren’t privy to.

        A client’s workers have little to do at night, so they watch videos or listen to Spotify. Otherwise I’d trash it. I won’t put it on my own computers.

        LikeLiked by 1 person

        • 10
          hoakley on September 17, 2021 at 9:19 am

          Ah – it doesn’t identify itself as Spotify, but a helper. What list do you see?
          Howard

          LikeLike

        • 11
          Pico on September 18, 2021 at 7:05 am

          There is another native and valid way that apps can make themselves launch at login using the Service Management framework which isn’t visible in the Login Items list in System Preferences. In fact, I believe it’s actually the only valid way that a Sandboxed app on the App Store is allowed to make itself launch at login.

          When an app makes itself launch at login this way, it isn’t visible anywhere except in the apps own settings and can only be undone by the app itself. I haven’t investigated Spotify, but it sounds like it may be use this technique.

          It looks like this post explains this Service Management framework technique pretty well: https://jogendra.dev/implementing-launch-at-login-feature-in-macos-apps

          In this case, I really think it’s more on Apple rather than 3rd party app developers that there is no way for a user to view and edit the apps that have been set to launch at login this way. They should be included in the Login Items list in System Preferences like the rest of the apps that have been manually added there. It is a different technique, but it is valid and Apple should make it more transparent, viewable, and controllable by users.

          If Spotify is in fact using this technique, and only chose to use it for its opaqueness, then shame on them. It’s also absurd and wrong that Spotify sets itself to launch at login by default as well.

          LikeLiked by 2 people

        • 12
          Samuel Herschbein on September 18, 2021 at 7:25 am

          Pico->

          Thank you, I learned something today. What I find infuriating is that Spotify won’t let you access any preferences until you log into their service. For the user, the only way to stop Spotify from launching is to either 1) create a Spotify account, or 2) delete the app. That’s strong-arming and why I consider it unconscionable.

          LikeLiked by 2 people

        • 13
          hoakley on September 18, 2021 at 8:43 am

          As I wrote in my reply to Pico, as far as I can see this app is an Electron app anyway, so probably not something that you’d want on a Mac in the first place.
          Howard.

          LikeLike

        • 14
          brightlondon on September 18, 2021 at 8:37 am

          Aha! Thank you Pico. This is what I have been searching for. I spent ages trying to figure out how an app was getting launched at login, yet was not in Login Items and had no LaunchAgent. Uninstalling it ended up being the only way to stop the behaviour, since the app did NOT provide a user preference to allow the user to choose whether they wanted it run at login.

          Since Apple has not provided any means for users to remove items that start themselves through the Service Management framework, I wonder if there is a possibility for a 3rd party tool to provide that control? Or only the app that set itself to launch at login has the entitlement to remove itself again?

          I do worry that this will end up being a good method for malware to make it harder for users to detect its presence and prevent it running. At least with malware that uses a LaunchAgent it’s easy to spot something unwanted.

          LikeLiked by 1 person

        • 15
          hoakley on September 18, 2021 at 8:45 am

          I think that only the app itself can disable its own automatic launch as a hidden LoginItem. Whether this offers a vulnerability, I don’t know: it would need more careful examination.
          Howard.

          LikeLike

        • 16
          hoakley on September 18, 2021 at 8:41 am

          Thank you.
          Yes, this is an underhand way for a sandboxed app to add itself to LoginItems – which is the launch mechanism it uses – without visibility or control for the user. And it is probably how the Spotify app does this, as it does have the requisite LoginItems folder containing a helper app which conforms to the description.
          The only control that a user has over this is provided in the app itself. If that doesn’t allow the user to disable the feature, then the only way to disable it is to trash the app, which is probably the wisest thing to do with Spotify anyway, as it’s an Electron app, I believe.
          Howard.

          LikeLike

  4. 17
    Simon on September 16, 2021 at 1:50 pm

    Thank you, Howard. I just got rid of my old Sierra-era login items pref. I’ll never go back to Sierra on this system (the hardware can’t, would be VM only) so why should I have this crud stick around. Plus, it would have already been backed up countless times by now if I eventually needed it for some other purpose.

    If only there were a central repository that would tell us which other preference files are no longer used and where their new counterparts reside. I’m a firm believer in keeping things lean and clean, but I hesitate installing vanilla from scratch and setting up everything again by hand (it’s just too much work). Even if an old pref file won’t screw up my Mac, the clutter can confuse and make focus difficult when troubleshooting. And that indeed will affect how well my Mac runs. 😉

    LikeLiked by 2 people

    • 18
      Dakotamoons on September 16, 2021 at 3:01 pm

      . . . . the word “bloated” is coming to mind, and possibly due to a need for “backward OS compatibility?” I too remember the days when these issue were simple and straightforward. As with Windoz, I sometimes feel “more is less.” Oh well. What will be, will be.

      LikeLiked by 1 person

    • 19
      hoakley on September 16, 2021 at 5:56 pm

      Thank you.
      I’ll be back tomorrow with some suggestions for housekeeping.
      Howard.

      LikeLike

·Comments are closed.

Quick Links

  • Downloads
  • Mac Troubleshooting Summary
  • M1 & M2 Macs
  • Mac problem-solving
  • Painting topics
  • Painting
  • Long Reads

Search

Monthly archives

  • January 2023 (72)
  • December 2022 (74)
  • November 2022 (72)
  • October 2022 (76)
  • September 2022 (72)
  • August 2022 (75)
  • July 2022 (76)
  • June 2022 (73)
  • May 2022 (76)
  • April 2022 (71)
  • March 2022 (77)
  • February 2022 (68)
  • January 2022 (77)
  • December 2021 (75)
  • November 2021 (72)
  • October 2021 (75)
  • September 2021 (76)
  • August 2021 (75)
  • July 2021 (75)
  • June 2021 (71)
  • May 2021 (80)
  • April 2021 (79)
  • March 2021 (77)
  • February 2021 (75)
  • January 2021 (75)
  • December 2020 (77)
  • November 2020 (84)
  • October 2020 (81)
  • September 2020 (79)
  • August 2020 (103)
  • July 2020 (81)
  • June 2020 (78)
  • May 2020 (78)
  • April 2020 (81)
  • March 2020 (86)
  • February 2020 (77)
  • January 2020 (86)
  • December 2019 (82)
  • November 2019 (74)
  • October 2019 (89)
  • September 2019 (80)
  • August 2019 (91)
  • July 2019 (95)
  • June 2019 (88)
  • May 2019 (91)
  • April 2019 (79)
  • March 2019 (78)
  • February 2019 (71)
  • January 2019 (69)
  • December 2018 (79)
  • November 2018 (71)
  • October 2018 (78)
  • September 2018 (76)
  • August 2018 (78)
  • July 2018 (76)
  • June 2018 (77)
  • May 2018 (71)
  • April 2018 (67)
  • March 2018 (73)
  • February 2018 (67)
  • January 2018 (83)
  • December 2017 (94)
  • November 2017 (73)
  • October 2017 (86)
  • September 2017 (92)
  • August 2017 (69)
  • July 2017 (81)
  • June 2017 (76)
  • May 2017 (90)
  • April 2017 (76)
  • March 2017 (79)
  • February 2017 (65)
  • January 2017 (76)
  • December 2016 (75)
  • November 2016 (68)
  • October 2016 (76)
  • September 2016 (78)
  • August 2016 (70)
  • July 2016 (74)
  • June 2016 (66)
  • May 2016 (71)
  • April 2016 (67)
  • March 2016 (71)
  • February 2016 (68)
  • January 2016 (90)
  • December 2015 (96)
  • November 2015 (103)
  • October 2015 (119)
  • September 2015 (115)
  • August 2015 (117)
  • July 2015 (117)
  • June 2015 (105)
  • May 2015 (111)
  • April 2015 (119)
  • March 2015 (69)
  • February 2015 (54)
  • January 2015 (39)

Tags

APFS Apple AppleScript Apple silicon backup Big Sur Blake bug Catalina Consolation Console diagnosis Disk Utility Doré El Capitan extended attributes Finder firmware Gatekeeper Gérôme HFS+ High Sierra history of painting iCloud Impressionism iOS landscape LockRattler log logs M1 Mac Mac history macOS macOS 10.12 macOS 10.13 macOS 10.14 macOS 10.15 macOS 11 macOS 12 macOS 13 malware Mojave Monet Monterey Moreau MRT myth narrative OS X Ovid painting Pissarro Poussin privacy realism Renoir riddle Rubens Sargent scripting security Sierra SilentKnight SSD Swift symbolism Time Machine Turner update upgrade Ventura xattr Xcode XProtect

Statistics

  • 13,754,779 hits
Blog at WordPress.com.
Footer navigation
  • About & Contact
  • Macs
  • Painting
  • Language
  • Tech
  • Life
  • General
  • Downloads
  • Mac problem-solving
  • Extended attributes (xattrs)
  • Painting topics
  • Hieronymus Bosch
  • English language
  • LockRattler: 10.12 Sierra
  • LockRattler: 10.13 High Sierra
  • LockRattler: 10.11 El Capitan
  • Updates: El Capitan
  • Updates: Sierra, High Sierra, Mojave, Catalina, Big Sur
  • LockRattler: 10.14 Mojave
  • SilentKnight, silnite, LockRattler, SystHist & Scrub
  • DelightEd & Podofyllin
  • xattred, Metamer, Sandstrip & xattr tools
  • 32-bitCheck & ArchiChect
  • T2M2, Ulbow, Consolation and log utilities
  • Cirrus & Bailiff
  • Taccy, Signet, Precize, Alifix, UTIutility, Sparsity, alisma
  • Revisionist & DeepTools
  • Text Utilities: Nalaprop, Dystextia and others
  • PDF
  • Keychains & Permissions
  • LockRattler: 10.15 Catalina
  • Updates
  • Spundle, Cormorant, Stibium, Dintch, Fintch and cintch
  • Long Reads
  • Mac Troubleshooting Summary
  • LockRattler: 11.0 Big Sur
  • M1 & M2 Macs
  • Mints: a multifunction utility
  • LockRattler: 12.x Monterey
  • VisualLookUpTest
  • Virtualisation on Apple silicon
  • LockRattler: 13.x Ventura
Secondary navigation
  • Search

Post navigation

Francisco Goya: Repaying debts
Characters in Painted Stories: 1 Introduction

Begin typing your search above and press return to search. Press Esc to cancel.

  • Follow Following
    • The Eclectic Light Company
    • Join 3,127 other followers
    • Already have a WordPress.com account? Log in now.
    • The Eclectic Light Company
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Copy shortlink
    • Report this content
    • View post in Reader
    • Manage subscriptions
    • Collapse this bar
 

Loading Comments...
 

    %d bloggers like this: