Mac Startup Apps: How to reset launchservice database
When developing mac startup apps, it is common to create redundant startup registration in your machine. In this post, I will give you a tip on how to remove these redundant items. Before that, let's look at how we register launch services programmatically.
How are Launch Services registered?
SMLoginItemSetEnabled is a function ( in Service Management Framework) that registers macOS applications to launch on startup.
SMLoginItemSetEnabled accepts 2 parameters:
- an identifier - helper tool identifier in the main app bundle’s Contents/Library/LoginItems directory.
- an enable flag - True/False state that instructs launch services to register/unregister your application for auto-start.
Duplicate entries in launch services
While testing SMLoginItemSetEnabled, it is common to have multiple registrations in launch services.
Multiple registrations of the same identifier can cause your app to not startup and makes debugging difficult. Luckily we can use the command-line tool lsregister from LaunchServices.framework to remove duplicate entries.
Finding and removing duplicate entries from launch services
To reduce the typing, I would like to create an alias for lsregister.
alias lsregister=/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister
Find all entries that starts with your application name.
lsregister -dump|grep path: | grep <YOUR APPLICATION NAME>
The command above should provide the path of all entries of your application.
For each path, execute the same command with an option -u
to delete it.
lsregister -u <Path>
Once you have deleted all the duplicate entries, your application's launch service should work properly again.
Reference:
Webmentions
Want to respond? Reply, like, reply or bookmark on Twitter :)