How to uninstall BOX drive using script

New Contributor
I have tried below one but isn't working, Any ideas?

$( scutil <<< "show State:/Users/ConsoleUser" | awk '/Name 😕 && ! /loginwindow/ { print $3 }' )
if [ -d "${testDirectory}" ]; then
echo "${appname} is installed; quit if running ..."
     if [[ $(ps axc | grep "$appname") != "" ]]; then
     echo "Box running, Quitting ..."
     sudo /usr/bin/osascript -e 'quit app "'"${appname}"'"'
     sudo pkill $appname
     echo "Box not running, exiting..."
sudo -u $logged_in_user /Library/Application\ Support/Box/uninstall_box_drive

Valued Contributor

Does the Box uninstaller not work? 

/Library/Application Support/Box/Uninstaller

Thanks for your response Andrew.
Have been tried and it's not working.

Here is my working policy


Screenshot 2021-09-23 at 19.47.54.png

Thanks @geoff_widdowson! In my initial testing I didn't include the kill process for Box. But not only that, I was running

/Library/Application\ Support/Box/uninstall_box_drive (without the _r) (just as the Box article states) as a policy command, and it kept erroring out mentioning not to use Sudo. I wasn't entering sudo in the command at all. Anyways, your process seemed to have uninstalled Box, and so thanks for your help. 

Your policy didn't work for me (as of version 2.26.330). It still kept saying not to run it with sudo. I ended up removing the "Search for Process" entry and the "kill process if found". I used this in the Command box:

killall Box ; /Library/Application\ Support/Box/uninstall_box_drive_r

and that worked.

What is the difference between the 3 different uninstall tools in AppSupport/Box/?