# Created by Matteo Rattotti on 13/03/06. # Copyright (c) 2006 Matteo Rattotti. All rights reserved. # Contact matteo.rattotti@gmail.com for any problem # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. from Foundation import * from AppKit import * import os def isOnStartUp(app): try: releaseP = NSAutoreleasePool.alloc().init() mBund = NSBundle.mainBundle() path = mBund.bundlePath() defs = NSUserDefaults.standardUserDefaults() loginWindowPref = defs.persistentDomainForName_("loginwindow").mutableCopy() try: len(loginWindowPref) except: loginWindowPref = {} loginItems = loginWindowPref.objectForKey_('AutoLaunchedApplicationDictionary').mutableCopy() try: len(loginItems) except: loginItems = {} for item in loginItems: itemPath = os.path.expanduser(item['Path']) res = itemPath.find(app) if res != -1: return 1 else: pass except: return 0 def setAppOnStartUp(app, set): releaseP = NSAutoreleasePool.alloc().init() mBund = NSBundle.mainBundle() path = mBund.bundlePath() defs = NSUserDefaults.standardUserDefaults() loginWindowPref = defs.persistentDomainForName_("loginwindow").mutableCopy() try: len(loginWindowPref) except: loginWindowPref = {} loginItems = loginWindowPref.objectForKey_('AutoLaunchedApplicationDictionary').mutableCopy() try: len(loginItems) except: loginItems = {} foundOne = 0 for item in loginItems: itemPath = os.path.expanduser(item['Path']) res = itemPath.find(app) if res != -1: loginItems.removeObjectIdenticalTo_(item) foundOne = 1 else: pass if set: launchDict = {'Hide':0, 'Path':path} loginItems.insertObject_atIndex_(launchDict, 0) loginWindowPref.setObject_forKey_(loginItems, 'AutoLaunchedApplicationDictionary') defs.setPersistentDomain_forName_(loginWindowPref, "loginwindow") defs.synchronize() releaseP.release()