All Projects → sindresorhus → Launchatlogin

sindresorhus / Launchatlogin

Licence: mit
Add “Launch at Login” functionality to your macOS app in seconds

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Launchatlogin

Zephyr
Effortlessly synchronize UserDefaults over iCloud.
Stars: ✭ 722 (-13.74%)
Mutual labels:  carthage
Dockprogress
Show progress in your app's Dock icon
Stars: ✭ 813 (-2.87%)
Mutual labels:  carthage
Swipemenuviewcontroller
Swipable tab and menu View and ViewController.
Stars: ✭ 926 (+10.63%)
Mutual labels:  carthage
Defaults
Swifty and modern UserDefaults
Stars: ✭ 734 (-12.31%)
Mutual labels:  carthage
Statusalert
Display Apple system-like self-hiding status alerts. It is well suited for notifying user without interrupting user flow in iOS-like way.
Stars: ✭ 809 (-3.35%)
Mutual labels:  carthage
Preferences
⚙ Add a preferences window to your macOS app in minutes
Stars: ✭ 898 (+7.29%)
Mutual labels:  carthage
Koyomi
Simple customizable calendar component in Swift 📆
Stars: ✭ 716 (-14.46%)
Mutual labels:  carthage
Imagescout
A Swift implementation of fastimage. Supports PNG, GIF, and JPEG.
Stars: ✭ 940 (+12.31%)
Mutual labels:  carthage
Bfkit
BFKit is a collection of useful classes and categories to develop Apps faster.
Stars: ✭ 811 (-3.11%)
Mutual labels:  carthage
Protobuf Swift
Google ProtocolBuffers for Apple Swift
Stars: ✭ 925 (+10.51%)
Mutual labels:  carthage
Blockhook
Hook Objective-C blocks. A powerful AOP tool.
Stars: ✭ 742 (-11.35%)
Mutual labels:  carthage
Xlpagertabstrip
Android PagerTabStrip for iOS.
Stars: ✭ 6,671 (+697.01%)
Mutual labels:  carthage
Imgix Swift
A Swift client library for generating URLs with imgix
Stars: ✭ 19 (-97.73%)
Mutual labels:  carthage
Rome
Carthage cache for S3, Minio, Ceph, Google Storage, Artifactory and many others
Stars: ✭ 724 (-13.5%)
Mutual labels:  carthage
Cascadingtabledelegate
A no-nonsense way to write cleaner UITableViewDelegate and UITableViewDataSource in Swift.
Stars: ✭ 931 (+11.23%)
Mutual labels:  carthage
Gradients
🌔 A curated collection of splendid 180+ gradients made in swift
Stars: ✭ 719 (-14.1%)
Mutual labels:  carthage
Sdwebimageflplugin
A SDWebImage plugin to support GIF using FLAnimatedImage and category
Stars: ✭ 16 (-98.09%)
Mutual labels:  carthage
Tbactionsheet
A Custom&Powerful Action Sheet For iOS. 一个 ActionSheet 满足所有样式!超高自由度的可定制!
Stars: ✭ 942 (+12.54%)
Mutual labels:  carthage
Mixpanel Iphone
iPhone tracking library for Mixpanel Analytics
Stars: ✭ 939 (+12.19%)
Mutual labels:  carthage
Ratelimit
Simple utility for only executing code every so often.
Stars: ✭ 918 (+9.68%)
Mutual labels:  carthage

LaunchAtLogin

Add “Launch at Login” functionality to your macOS app in seconds

It's usually quite a convoluted and error-prone process to add this. No more!

This package works with both sandboxed and non-sandboxed apps and it's App Store compatible and used in apps like Plash, Dato, Lungo, and Battery Indicator.

Requirements

  • macOS 10.12+
  • Xcode 12+
  • Swift 5.3+

Install

Swift Package Manager

Xcode 12+ required.

.package(url: "https://github.com/sindresorhus/LaunchAtLogin", from: "4.0.0")

Carthage

Warning: Carthage is not recommended. Support for it will be removed at some point in the future.

github "sindresorhus/LaunchAtLogin"

Usage

Add a new "Run Script Phase" below "Embed Frameworks" in "Build Phases" with the following:

Swift Package Manager

"${BUILT_PRODUCTS_DIR}/LaunchAtLogin_LaunchAtLogin.bundle/Contents/Resources/copy-helper-swiftpm.sh"

Carthage

"${PROJECT_DIR}/Carthage/Build/Mac/LaunchAtLogin.framework/Resources/copy-helper.sh"

Use it in your app

No need to store any state to UserDefaults.

Note that the Mac App Store 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.

As static property

import LaunchAtLogin

print(LaunchAtLogin.isEnabled)
//=> false

LaunchAtLogin.isEnabled = true

print(LaunchAtLogin.isEnabled)
//=> true

SwiftUI

This 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.

struct ContentView: View {
	var body: some View {
		LaunchAtLogin.Toggle()
	}
}

The default label is "Launch at login", but it can be overridden for localization and other needs:

struct ContentView: View {
	var body: some View {
		LaunchAtLogin.Toggle {
			Text("Launch at login")
		}
	}
}

Alternatively, you can use LaunchAtLogin.observable as a binding with @ObservedObject:

import SwiftUI
import LaunchAtLogin

struct ContentView: View {
	@ObservedObject private var launchAtLogin = LaunchAtLogin.observable

	var body: some View {
		Toggle("Launch at login", isOn: $launchAtLogin.isEnabled)
	}
}

Combine

Just subscribe to LaunchAtLogin.publisher:

import Combine
import LaunchAtLogin

final class ViewModel {
	private var isLaunchAtLoginEnabled = LaunchAtLogin.isEnabled
	private var cancellables = Set<AnyCancellable>()

	func bind() {
		LaunchAtLogin
			.publisher
			.assign(to: \.isLaunchAtLoginEnabled, on: self)
			.store(in: &cancellables)
	}
}

Storyboards

Bind the control to the LaunchAtLogin.kvo exposed property:

import Cocoa
import LaunchAtLogin

final class ViewController: NSViewController {
	@objc dynamic var launchAtLogin = LaunchAtLogin.kvo
}

How does it work?

The framework bundles the helper app needed to launch your app and copies it into your app at build time.

FAQ

I'm getting a “No such file or directory” error when archiving my app

Please ensure that the LaunchAtLogin run script phase is still below the “Embed Frameworks” phase. The order could have been accidentally changed.

The build error usually presents itself as:

cp: […]/Resources/LaunchAtLoginHelper.app: No such file or directory
rm: […]/Resources/copy-helper.sh: No such file or directory
Command PhaseScriptExecution failed with a nonzero exit code

The size of my app increased after adding LaunchAtLogin when using Carthage

The bundled launcher app is written in Swift and hence needs to embed the Swift runtime libraries. If your project targets macOS 10.14.4 or later, you can avoid embedding the Swift runtime libraries. First, open ./Carthage/Checkouts/LaunchAtLogin/LaunchAtLogin.xcodeproj and set the deployment target to the same as your app, and then run $ carthage build. You'll have to do this each time you update LaunchAtLogin.

This is not a problem when using Swift Package Manager.

My app doesn't show up in “System Preferences › Users & Groups › Login Items”

This is the expected behavior, unfortunately.

My app doesn't launch at login when testing

This 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.

Some things you can try:

  • Bump the version & build of your app so macOS is more likely to pick it.
  • Delete the DerivedData directory.
  • Ensure you don't have any other builds laying around somewhere.

Some helpful Stack Overflow answers:

Can you support CocoaPods?

CocoaPods used to be supported, but it did not work well and there was no easy way to fix it, so support was dropped. Even though you mainly use CocoaPods, you can still use Carthage just for this package without any problems.

I'm getting a 'SMCopyAllJobDictionaries' was deprecated in OS X 10.10 warning

Apple deprecated that API without providing an alternative. Apple engineers have stated that it's still the preferred API to use. I plan to use it as long as it's available. There are workarounds I can implement if Apple ever removes the API, so rest assured, this module will be made to work even then. If you want to see this resolved, submit a Feedback Assistant report with the following text. There's unfortunately still no way to suppress warnings in Swift.

Related

  • Defaults - Swifty and modern UserDefaults
  • Preferences - Add a preferences window to your macOS app in minutes
  • KeyboardShortcuts - Add user-customizable global keyboard shortcuts to your macOS app
  • DockProgress - Show progress in your app's Dock icon
  • create-dmg - Create a good-looking DMG for your macOS app in seconds
  • More…
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].