{"id":13466069,"url":"https://github.com/sindresorhus/LaunchAtLogin-Legacy","last_synced_at":"2025-03-25T21:31:11.445Z","repository":{"id":23374981,"uuid":"98812730","full_name":"sindresorhus/LaunchAtLogin-Legacy","owner":"sindresorhus","description":"Add “Launch at Login” functionality to your macOS app in seconds","archived":false,"fork":false,"pushed_at":"2024-06-25T00:03:49.000Z","size":6774,"stargazers_count":1563,"open_issues_count":14,"forks_count":123,"subscribers_count":15,"default_branch":"main","last_synced_at":"2024-10-29T15:39:56.570Z","etag":null,"topics":["macos","swift","swift-package"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","buy_me_a_coffee":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2017-07-30T17:12:19.000Z","updated_at":"2024-10-29T13:08:49.000Z","dependencies_parsed_at":"2023-10-16T11:08:15.052Z","dependency_job_id":"bf3ed067-5b68-487a-a389-7c7fce4d93c1","html_url":"https://github.com/sindresorhus/LaunchAtLogin-Legacy","commit_stats":{"total_commits":68,"total_committers":9,"mean_commits":7.555555555555555,"dds":"0.19117647058823528","last_synced_commit":"d811817ce35d74872a1170c851cab243a2b8b559"},"previous_names":["sindresorhus/launchatlogin-legacy","sindresorhus/launchatlogin"],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2FLaunchAtLogin-Legacy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2FLaunchAtLogin-Legacy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2FLaunchAtLogin-Legacy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2FLaunchAtLogin-Legacy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/LaunchAtLogin-Legacy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222091826,"owners_count":16929715,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["macos","swift","swift-package"],"created_at":"2024-07-31T15:00:38.813Z","updated_at":"2024-10-29T18:30:47.864Z","avatar_url":"https://github.com/sindresorhus.png","language":"Swift","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://buymeacoffee.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["Libs","Swift","macos","swift","Recently Updated"],"sub_categories":["System","[Feb 04, 2025](/content/2025/02/04/README.md)"],"readme":"# LaunchAtLogin\n\n\u003e Add “Launch at Login” functionality to your macOS app in seconds\n\n**If your app targets macOS 13 or later, check out [this modern version](https://github.com/sindresorhus/LaunchAtLogin-Modern) instead.**\n\nIt's usually quite a [convoluted and error-prone process](before-after.md) to add this (on macOS 12 and older). **No more!**\n\nThis package works with both sandboxed and non-sandboxed apps and it's App Store compatible and used in apps like [Plash](https://github.com/sindresorhus/Plash), [Dato](https://sindresorhus.com/dato), [Lungo](https://sindresorhus.com/lungo), and [Battery Indicator](https://sindresorhus.com/battery-indicator).\n\n**This package uses the new [`SMAppService`](https://developer.apple.com/documentation/servicemanagement/smappservice/3945412-mainapp) on macOS 13+ and [`SMLoginItemSetEnabled`](https://developer.apple.com/documentation/servicemanagement/1501557-smloginitemsetenabled) on older macOS versions.**\n\n### Why should I use this package now that [`SMAppService`](https://developer.apple.com/documentation/servicemanagement/smappservice/3945412-mainapp?changes=latest_minor) exists?\n\n- Backwards compatibility with older macOS versions\n- Nicer API\n- Included SwiftUI component\n\n## Requirements\n\nmacOS 10.13+\n\n## Install\n\nAdd `https://github.com/sindresorhus/LaunchAtLogin-Legacy` in the [“Swift Package Manager” tab in Xcode](https://developer.apple.com/documentation/xcode/adding_package_dependencies_to_your_app).\n\n## Usage\n\n**Skip this step if your app targets macOS 13 or later.**\n\nAdd a new [“Run Script Phase”](http://stackoverflow.com/a/39633955/64949) **below** (not into) “Copy Bundle Resources” in “Build Phases” with the following:\n\n```sh\n\"${BUILT_PRODUCTS_DIR}/LaunchAtLogin_LaunchAtLogin.bundle/Contents/Resources/copy-helper-swiftpm.sh\"\n```\n\nAnd uncheck “Based on dependency analysis”.\n\nThe build phase cannot run with \"User Script Sandboxing\" enabled. With Xcode 15 or newer where it is enabled by default, disable \"User Script Sandboxing\" in build settings. \n\n*(It needs some extra works to have our script to comply with the build phase sandbox.)*\n*(I would name the run script `Copy “Launch at Login Helper”`)*\n\n### Use it in your app\n\nNo need to store any state to UserDefaults.\n\n*Note that the [Mac App Store guidelines](https://developer.apple.com/app-store/review/guidelines/) requires “launch at login” functionality to be enabled in response to a user action. This is usually solved by making it a preference that is disabled by default. Many apps also let the user activate it in a welcome screen.*\n\n#### As static property\n\n```swift\nimport LaunchAtLogin\n\nprint(LaunchAtLogin.isEnabled)\n//=\u003e false\n\nLaunchAtLogin.isEnabled = true\n\nprint(LaunchAtLogin.isEnabled)\n//=\u003e true\n```\n\n#### SwiftUI\n\nThis package comes with a `LaunchAtLogin.Toggle` view which is like the built-in `Toggle` but with a predefined binding and label. Clicking the view toggles “launch at login” for your app.\n\n```swift\nstruct ContentView: View {\n\tvar body: some View {\n\t\tLaunchAtLogin.Toggle()\n\t}\n}\n```\n\nThe default label is `\"Launch at login\"`, but it can be overridden for localization and other needs:\n\n```swift\nstruct ContentView: View {\n\tvar body: some View {\n\t\tLaunchAtLogin.Toggle {\n\t\t\tText(\"Launch at login\")\n\t\t}\n\t}\n}\n```\n\nAlternatively, you can use `LaunchAtLogin.observable` as a binding with `@ObservedObject`:\n\n```swift\nimport SwiftUI\nimport LaunchAtLogin\n\nstruct ContentView: View {\n\t@ObservedObject private var launchAtLogin = LaunchAtLogin.observable\n\n\tvar body: some View {\n\t\tToggle(\"Launch at login\", isOn: $launchAtLogin.isEnabled)\n\t}\n}\n```\n\n#### Combine\n\nJust subscribe to `LaunchAtLogin.publisher`:\n\n```swift\nimport Combine\nimport LaunchAtLogin\n\nfinal class ViewModel {\n\tprivate var isLaunchAtLoginEnabled = LaunchAtLogin.isEnabled\n\tprivate var cancellables = Set\u003cAnyCancellable\u003e()\n\n\tfunc bind() {\n\t\tLaunchAtLogin\n\t\t\t.publisher\n\t\t\t.assign(to: \\.isLaunchAtLoginEnabled, on: self)\n\t\t\t.store(in: \u0026cancellables)\n\t}\n}\n```\n\n#### Swift Concurrency\n\nUse [`LaunchAtLogin.publisher.values`](https://developer.apple.com/documentation/combine/publisher/values-1dm9r).\n\n#### Storyboards\n\nBind the control to the `LaunchAtLogin.kvo` exposed property:\n\n```swift\nimport Cocoa\nimport LaunchAtLogin\n\nfinal class ViewController: NSViewController {\n\t@objc dynamic var launchAtLogin = LaunchAtLogin.kvo\n}\n```\n\n\u003cimg src=\"storyboard-binding.png\" width=\"445\"\u003e\n\n## How does it work?\n\nOn macOS 12 and earlier, the package bundles the helper app needed to launch your app and copies it into your app at build time. On macOS 13 and later, it calls the built-in API.\n\n## FAQ\n\n#### I'm getting a “No such file or directory” error when archiving my app\n\nPlease ensure that the LaunchAtLogin run script phase is still below the “Embed Frameworks” phase. The order could have been accidentally changed.\n\nThe build error usually presents itself as:\n\n```\ncp: […]/Resources/LaunchAtLoginHelper.app: No such file or directory\nrm: […]/Resources/copy-helper.sh: No such file or directory\nCommand PhaseScriptExecution failed with a nonzero exit code\n```\n\n#### My app doesn't show up in “System Preferences › Users \u0026 Groups › Login Items”\n\n[This is the expected behavior](https://stackoverflow.com/a/15104481/64949), unfortunately.\n\nHowever, it will show there on macOS 13 and later.\n\n#### My app doesn't launch at login when testing\n\nThis is usually caused by having one or more older builds of your app laying around somewhere on the system, and macOS picking one of those instead, which doesn't have the launch helper, and thus fails to start.\n\nSome things you can try:\n- Bump the version \u0026 build of your app so macOS is more likely to pick it.\n- Delete the [`DerivedData` directory](https://mgrebenets.github.io/mobile%20ci/2015/02/01/xcode-derived-data).\n- Ensure you don't have any other builds laying around somewhere.\n\nSome helpful Stack Overflow answers:\n- https://stackoverflow.com/a/43281810/64949\n- https://stackoverflow.com/a/51683190/64949\n- https://stackoverflow.com/a/53110832/64949\n- https://stackoverflow.com/a/53110852/64949\n\n#### I can't see the `LaunchAtLogin.bundle` in my debug build or I get a notarization error for developer ID distribution\n\nAs discussed [here](https://github.com/sindresorhus/LaunchAtLogin-Legacy/issues/50), this package tries to determine if you're making a release or debug build and clean up its install accordingly. If your debug build is missing the bundle or, conversely, your release build has the bundle and it causes a code signing error, that means this has failed.\n\nThe script's determination is based on the “Build Active Architecture Only” flag in build settings. If this is set to `YES`, then the script will package LaunchAtLogin for a debug build. You must set this flag to `NO` if you plan on distributing the build with codesigning.\n\n## Related\n\n- [Defaults](https://github.com/sindresorhus/Defaults) - Swifty and modern UserDefaults\n- [KeyboardShortcuts](https://github.com/sindresorhus/KeyboardShortcuts) - Add user-customizable global keyboard shortcuts to your macOS app\n- [DockProgress](https://github.com/sindresorhus/DockProgress) - Show progress in your app's Dock icon\n- [create-dmg](https://github.com/sindresorhus/create-dmg) - Create a good-looking DMG for your macOS app in seconds\n- [More…](https://github.com/search?q=user%3Asindresorhus+language%3Aswift+archived%3Afalse\u0026type=repositories)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2FLaunchAtLogin-Legacy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2FLaunchAtLogin-Legacy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2FLaunchAtLogin-Legacy/lists"}