I create project for os x application with xpcservices that run by loginItems. that's mean the service is founded in the app in the path:{APP_NAME}.app/Contents/Library/LoginItems and who is responsible for run the service is the the main app:
NSXPCConnection *connection = [[NSXPCConnection alloc] initWithLoginItemName:@"{SERVICE_NAME}.app" error:&error];
I builded uninstaller, for deleting all the files that I installed. and I need to remove the service. the command I used for it :
launchctl remove SERVICE_NAME
this is works fine if I run it from the terminal, but if i run it from script it's remove the service from the "Activity Monitor" but the service still in launchctl list with status -5. so if I install new version its take the previous version that installed.
I run the script from xcode by NSTask
. there is no error. it's does what the script should do.
I even set the administrator privileges:
/usr/bin/osascript -e 'do shell script \"SCRIPT_NAME args 2>&1 etc\" with administrator privileges'
Why it's not remove like I did it in the terminal ?
p.s: its works when run it from Xcode (even the app is in release mode)
To remove correctly the login item you should do it in the code : pass false in
SMLoginItemSetEnabled
: