2

I want to check whether a particular Mac app has been codesigned by my certificate authority or not in the terminal.

For that, I am having this code, but I am getting the entire codesign output and 1 at the end for some reason.

codesign -dvv --deep MayApp.app | grep "Authority=Mac Developer: My Certificate (5JFD6LWV27)"
if [ $? -eq 0 ]; then
    echo "App has been signed successfully by my cert!"
else
    echo "App is not signed correctly!"
fi

Any help would highly be appreciated.

Thanks!

5
  • Use grep -q to suppress output
    – anubhava
    May 5, 2016 at 18:16
  • Thanks for chiming in here @anubhava. I tried -q but it didn't suppress the output for me.
    – Dave Ronak
    May 5, 2016 at 18:22
  • For short, I tried this: codesign -dvv --deep MayApp.app | grep -q "Authority=Mac Developer: My Certificate (5JFD6LWV27)"; echo $?
    – Dave Ronak
    May 5, 2016 at 18:28
  • Try: codesign -dvv --deep MayApp.app | grep -qF "Authority=Mac Developer: My Certificate (5JFD6LWV27)"
    – anubhava
    May 5, 2016 at 18:29
  • I tried that as well. Still, same output. Actually, I also tried grep -qFx
    – Dave Ronak
    May 5, 2016 at 18:30

1 Answer 1

2

Most likely your codesign is writing on stderr.

You can this snippet to pipeline both stdout/stderr to grep:

if codesign -dvv --deep MayApp.app 2>&1 | grep -qF "Authority=Mac Developer: My Certificate (5JFD6LWV27)"
then
   echo "App has been signed successfully by my cert!"
else
   echo "App is not signed correctly!"
fi
3
  • -bash: syntax error near unexpected token '&' when I tried this line: codesign -dvv --deep MayApp.app |& grep -qF "Authority=Mac Developer: My Certificate (5JFD6LWV27)"; echo $?
    – Dave Ronak
    May 5, 2016 at 18:41
  • This worked like a charm. Thanks a ton. Can you please explain your answer? Sorry, I am not that expert in bash scripting.
    – Dave Ronak
    May 5, 2016 at 18:54
  • 1
    Since codesign is writing output on stderr instead of stdout a simple pipe to grep is not working as grep is getting only stdout data from previous command. By doing 2>&1 we are first redirecting stderr to stdout and then grep is happy
    – anubhava
    May 5, 2016 at 19:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.