You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: readme.md
+19-35Lines changed: 19 additions & 35 deletions
Original file line number
Diff line number
Diff line change
@@ -2,31 +2,31 @@
2
2
3
3
> Add “Launch at Login” functionality to your macOS app in seconds
4
4
5
-
It's usually quite a [convoluted and error-prone process](before-after.md) to add this. **No more!**
5
+
**If your app targets macOS 13 or later, check out [this modern version](https://github.com/sindresorhus/LaunchAtLogin-Modern) instead.**
6
+
7
+
It's usually quite a [convoluted and error-prone process](before-after.md) to add this (on macOS 12 and older). **No more!**
6
8
7
9
This 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).
8
10
11
+
**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.**
12
+
13
+
### Why should I use this package now that [`SMAppService`](https://developer.apple.com/documentation/servicemanagement/smappservice/3945412-mainapp?changes=latest_minor) exists?
14
+
15
+
- Backwards compatibility with older macOS versions
16
+
- Nicer API
17
+
- Included SwiftUI component
18
+
9
19
## Requirements
10
20
11
21
macOS 10.13+
12
22
13
23
## Install
14
24
15
-
#### Swift Package Manager
16
-
17
25
Add `https://github.com/sindresorhus/LaunchAtLogin` in the [“Swift Package Manager” tab in Xcode](https://developer.apple.com/documentation/xcode/adding_package_dependencies_to_your_app).
18
26
19
-
#### Carthage
20
-
21
-
*Warning: Carthage is not recommended. Support for it will be removed at some point in the future.*
22
-
23
-
```
24
-
github "sindresorhus/LaunchAtLogin"
25
-
```
26
-
27
27
## Usage
28
28
29
-
#### Swift Package Manager
29
+
**Skip this step if your app targets macOS 13 or later.**
30
30
31
31
Add a new [“Run Script Phase”](http://stackoverflow.com/a/39633955/64949)**below** (not into) “Copy Bundle Resources” in “Build Phases” with the following:
32
32
@@ -38,16 +38,6 @@ And uncheck “Based on dependency analysis”.
38
38
39
39
*(I would name the run script `Copy “Launch at Login Helper”`)*
40
40
41
-
#### Carthage
42
-
43
-
Add a new [“Run Script Phase”](http://stackoverflow.com/a/39633955/64949)**below** (not into) “Embed Frameworks” in “Build Phases” with the following:
*(I would name the run script `Copy “Launch at Login Helper”`)*
50
-
51
41
### Use it in your app
52
42
53
43
No need to store any state to UserDefaults.
@@ -128,6 +118,10 @@ final class ViewModel {
128
118
}
129
119
```
130
120
121
+
#### Swift Concurrency
122
+
123
+
Use [`LaunchAtLogin.publisher.values`](https://developer.apple.com/documentation/combine/publisher/values-1dm9r).
124
+
131
125
#### Storyboards
132
126
133
127
Bind the control to the `LaunchAtLogin.kvo` exposed property:
@@ -145,7 +139,7 @@ final class ViewController: NSViewController {
145
139
146
140
## How does it work?
147
141
148
-
The package bundles the helper app needed to launch your app and copies it into your app at build time.
142
+
On 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.
149
143
150
144
## FAQ
151
145
@@ -161,16 +155,12 @@ rm: […]/Resources/copy-helper.sh: No such file or directory
161
155
Command PhaseScriptExecution failed with a nonzero exit code
162
156
```
163
157
164
-
#### The size of my app increased after adding `LaunchAtLogin` when using Carthage
165
-
166
-
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`.
167
-
168
-
This is not a problem when using Swift Package Manager.
169
-
170
158
#### My app doesn't show up in “System Preferences › Users & Groups › Login Items”
171
159
172
160
[This is the expected behavior](https://stackoverflow.com/a/15104481/64949), unfortunately.
173
161
162
+
However, it will show there on macOS 13 and later.
163
+
174
164
#### My app doesn't launch at login when testing
175
165
176
166
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.
@@ -186,10 +176,6 @@ Some helpful Stack Overflow answers:
186
176
-https://stackoverflow.com/a/53110832/64949
187
177
-https://stackoverflow.com/a/53110852/64949
188
178
189
-
#### Can you support CocoaPods?
190
-
191
-
CocoaPods used to be supported, but [it did not work well](https://github.com/sindresorhus/LaunchAtLogin/issues/22) and there was no easy way to fix it, so support was dropped. Even though you mainly use CocoaPods, you can still use Swift Package Manager just for this package without any problems.
192
-
193
179
#### I can't see the `LaunchAtLogin.bundle` in my debug build or I get a notarization error for developer ID distribution
194
180
195
181
As discussed [here](https://github.com/sindresorhus/LaunchAtLogin/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.
@@ -200,8 +186,6 @@ The script's determination is based on the “Build Active Architecture Only”
200
186
201
187
-[Defaults](https://github.com/sindresorhus/Defaults) - Swifty and modern UserDefaults
202
188
-[KeyboardShortcuts](https://github.com/sindresorhus/KeyboardShortcuts) - Add user-customizable global keyboard shortcuts to your macOS app
0 commit comments