Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add login Items by code to mountain lion osx

I want to add login items programmatically in Mountain Lion (10.8).

Until now I was able to add login items by editing this plist:

/Users/test/Library/Preferences/loginwindow.plist

and adding items (path,name,hide) to AutoLaunchedApplicationDictionary dictionary in the OS doesn't work anymore. Items that are added to this dictionary are not launched on login. I see that the login items are saved in a file called: com.apple.loginitems.plist

but I don't understand how to add an item to this file. I tried to add the item to CustomListItems dictionary with parameters like name,path, hide but they were not launched on login.

Does anyone know how can I add from code login item?

like image 595
Tal Avatar asked Aug 23 '12 07:08

Tal


People also ask

How do I add a login item on a Mac?

On your Mac, choose Apple menu > System Preferences, then click Users & Groups . Select your user account, then click Login Items at the top of the window. Do any of the following: Add a login item: Click the Add button below the list of items, select a document, folder, app, server, or other item, then click Add.

Where are login items stored OSX?

So where exactly does Mac OS X store the data that it uses to create the Login Items list? It is stored in a preferences (. plist) file called loginwindow. plist, located in the ~/Library/Preferences folder (i.e., in your Home directory).


1 Answers

I understand you want to start your program automatically when your user logs in.

In older versions of OS X, it was possible to add login items manually by editing loginwindow.plist. Apple deprecated this approach when they added LaunchAgent and LaunchDaemon functionality to the OS.

Since you are using Mountain Lion, the correct way to have a program launch is to create a launchagent for it. This is a .plist file that you can use to tell OS X to a) perform some action (e.g.: launch /some/program.app) when b) a specific event occurs (e.g.: logging in, logging out, etc)

You will find Apple's official document on creation of LaunchAgents over here.

like image 179
original_username Avatar answered Sep 24 '22 06:09

original_username