I have a script that failed a policy because the result is:
Executing Policy Quit_ALL_Microsoft copy copy...
[STEP 1 of 1]
Running script Quit_ALL_Microsoft...
Script exit code: 0
Script result: 0:25: execution error: Microsoft Lync got an error: User canceled. (-128)
This result is fine but I want casper to ignore it and complete the policy
#!/bin/sh osascript -e 'quit app "Microsoft lync"'
First off, does it run and quit Lync? I'm going to guess it does not quit it. The reason is, there is an issue with the script to start with, which may be why you are getting that error. The main problem is that Applescript or osascript calls to a user session don't really work well when they are run from a policy. OS X doesn't like when a root level command tries to affect another user's space, like quitting an application run by the logged in user, especially when its done using Applescript commands.
You can try doing something like looking for the running process (Lync) and then using the kill command instead. I'm not a big fan of using kill or killall, but it may be the only way in the short term to not have it error on you.
Another more advanced way would be to pre install and load a user level LaunchAgent that watches for a trigger to run a script. The script can then do the osascript call to gracefully quit the applications you pass to it. Since LaunchAgent's run as the logged in user, this should work without errors.
If I'm off the mark on the above and its actually somehow working, but you want to avoid seeing the "error" text show up in the policy log, you'll probably need to add some error trapping to send errors to /dev/null or tell Applescript to ignore them, or they will get printed out in the script result. The jamf binary sees "error" and then thinks something went wrong. This has been a long long standing issue. Would really be great if this behavior was finally deprecated and removed from Casper as JAMF has been promising now for a while.
Well, kind of surprised its working at all, but, if it is, I'm not sure what the best way would be to ignore those errors. I'm not even sure why there would be any errors if its actually quitting Lync successfully.
Maybe something like the below, which I think should tell osascript to do something different on an error. I'm not the best Applescripter, so someone else here probably has a better answer for you to be honest.
#!/bin/sh osascript << EOF tell application "System Events" try quit application "Microsoft Lync" on error return end try end tell EOF