Cocoa Dialog

jbruno
New Contributor

Anyone have a step by step guide to using Cocoadialog for an environment. I have been looking around for a script to delete the keychain thru self service and the one I found uses Cocoadialog. Any help with this would be awesome! Thank you.

11 REPLIES 11

mm2270
Legendary Contributor III

So... what are you looking to do with it exactly? Just deleting the keychain? What user interaction steps in that process are you envisioning?
I have a boatload of different scripts I've posted here, and on my github and some that I've never posted that use cocoaDialog. I'm pretty sure I can help you use it effectively, but you'd need to clarify a little more what it is you want to do.

EDIT: I should also just say that, although I use cocoaDialog a lot, depending on your end goal, it may not be necessary to use it. Remember that any Casper managed Mac will also have jamfHelper and Management Action.app on them to use for basic messaging to the end user.

Look
Valued Contributor III

If your looking for very simple user interactions (i.e. Are you sure you want to delete the Keychain, Yes, No) you probably don't need Cocoadialog. Simple osascript calls will probably get it done, there are loads of examples if you google osascript dialog or if you let us know what your after I am sure someone here can post a snippet that does something similar.

Johnny_Kim
Contributor II

The script that I use to delete the keychain uses Cocoa dialog for prompts.

#!/bin/sh

#  keychain_removal.sh
#  
#
#   jkim on 2/24/14.
#

CD="/path/to/folder/CocoaDialog.app/Contents/MacOS/CocoaDialog"
loggedInUser=$(ls -l /dev/console|cut -d' ' -f4)

rm -f "/users/$loggedInUser/Library/Keychains/login.keychain"

if [ "$loggedInUser" != 'root' ]; then # Check if at the login window, if it is, the following code is skipped
#### CocoaDialog message box asking for the user to select restart
rv=`$CD msgbox --title "Restart Please" 
--text "To complete the Keychain Fix, a restart is required." 
--informative-text "It is important that you select Restart, but you may select Later to restart at a more convenient time." 
--no-newline --button1 "Restart" --button2 "Later" --float`
#### If the user selects restart, an apple script runs to run the Apple restart command. Gives the user a minute to cancel restart.
if [ "$rv" == "1" ]; then
echo "User selected Restart"
osascript -e 'tell application "loginwindow" to «event aevtrrst»'
elif [ "$rv" == "2" ]; then
echo "User selected Later"
exit
fi
else
echo "No User logged in. CocoaDialog not necessary"
fi

Heres a link to cocoa dialog documentation that explains what you can do with it.
https://mstratman.github.io/cocoadialog/#documentation

jbruno
New Contributor

@mm2270 I'm looking to give users/help desk the ability to push one button in Self Service to delete someone's keychain.

mm2270
Legendary Contributor III

Hi @jbruno OK, I get that part. My question really was what part of that Self Service policy would need user interaction or messaging? Deleting a file, which is what the login.keychain is, is a super simple task that a bash script can handle. Do you just need a message to come up at the end that would say something like "Your keychain has been removed" or something to that effect? If so, there really is no need to use cocoaDialog, as you already have several built in tools that can send up a simple dialog like that. Some examples are:

  • jamfHelper (/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper)
  • jamf binary (jamf displayMessage -message "Message goes here")
  • Management Action.app (/Library/Application Support/JAMF/bin/Management Action.app/Contents/MacOS/Management Action)

You won't find a bigger fan of the utility than me, but its important sometimes to step back and think carefully about what the end goal is and use the right tool for the job, or in this case, the tools you already have instead of trying to overcomplicate it.

If on the other hand, you need something that will show options, progress bars, file selection windows and such, then cocoaDialog might be the right choice, but so far in your description I haven't seen the need for it.

Lastly, if you are looking to use it so you can get your feet wet with using it for future dialoging needs, then that would be a valid case. I'm just not sure if that's why you were asking about it.

jbruno
New Contributor

@mm2270 Thanks again... All I'm looking for end the end is a script to delete the keychain, no need for a message for the user. Can you send me a link to your github scripts?

mm2270
Legendary Contributor III

My github link is in my JAMFNation profile.

If all you need is something to delete the current user's login.keychain file to run from Self Service, something like this should work. Its simple, and could really have additional checks added, but this is the basic idea.

#!/bin/sh

loggedInUser=$(stat -f%Su /dev/console)

rm "/Users/${loggedInUser}/Library/Keychains/login.keychain"

The thing is, deleting this should really be followed by a complete log out of the account, otherwise, weird stuff will likely start happening to the user. The login keychain stores a fair amount of stuff and deleting it and staying logged in will likely begin generating error messages that pop up.

cwaldrip
Valued Contributor

Are most people using 2.1.1 from 2006 or the 3.0.0-beta7 from 2012? Or is there a newer version elsewhere?

sean
Valued Contributor

Pashua, it's actively supported (last updated 2 weeks ago)

There's a couple of things CocoaDialog does that Pashua doesn't and for that I'd use it, but not fussed by version for those uses.

bentoms
Release Candidate Programs Tester

@mm2270 You might want to add the local items keychain too.

@cwaldrip I'm using @loceee's fork

cwaldrip
Valued Contributor

Thanks @bentoms