Skip to main content
Solved

JAMFhelper script help

  • November 14, 2014
  • 6 replies
  • 0 views

Forum|alt.badge.img+12

Hi all! I am working on something pretty simple, but I have gotten myself stuck and promise to give myself 5 lashes with a wet noodle for my oversight....

What I am trying to do is display a message to the user to clear the web cache or cancel the operation, if the user chooses to continue my script should run then display the completed message. If the user selects cancel the script should exit. I feel like I am missing something pretty basic. Thoughts?

#!/bin/sh

# the purpose of this script is to delete all browser caches.
#
#
# created by Pat B 11/3/14

CLEARCACHE='/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -title "Internet Browser Web Cache" -heading "Please exit all web pages before continuing" -alignHeading center -description "You web browser cache will be cleared when you click the button below.  This may take several minutes and you will be notified when the process completes. Thank you for your patience!" -icon /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarInfo.icns -button1 "Erase Cache" -button2 "Cancel" -defaultButton 1 -cancelButton 2'
USER=`who | grep console | awk '{print $1}'`

# If the user clicks Erase Cache

if [ "$CLEARCACHE" == "0" ]; then
        echo "Clearing Cache"
        sleep 2
        rm -R /Users/$USER/Library/Caches/Google 
        rm -R /Users/$USER/Library/Caches/Firefox 
        rm -R /Users/$USER/Library/Caches/com.apple.Safari
        /Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -title "Internet Browser Web Cache" -heading "Process Complete" -alignHeading center -description "Your web browser caches have been cleared for Firefox, Safari, and Google Chrome." -icon /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarSitesFolderIcon.icns -button1 " Exit " -defaultButton 1
            exit 1

# if the user clicks cancel
elif [ "$CLEARCACHE" == "2" ]; then
         echo "User canceled cache clear";   
     exit 1
fi

Best answer by davidacland

Might be a little different but I would do it this way:

USER=`who | grep console | awk '{print $1}'`

/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -title "Internet Browser Web Cache" -heading "Please exit all web pages before continuing" -alignHeading center -description "You web browser cache will be cleared when you click the button below.  This may take several minutes and you will be notified when the process completes. Thank you for your patience!" -icon /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarInfo.icns -button1 "Erase Cache" -button2 "Cancel" -defaultButton 1 -cancelButton 2

# If the user clicks Erase Cache

if [ "$?" == "0" ]; then
        echo "Clearing Cache"
        sleep 2
        rm -R /Users/$USER/Library/Caches/Google 
        rm -R /Users/$USER/Library/Caches/Firefox 
        rm -R /Users/$USER/Library/Caches/com.apple.Safari
        /Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -title "Internet Browser Web Cache" -heading "Process Complete" -alignHeading center -description "Your web browser caches have been cleared for Firefox, Safari, and Google Chrome." -icon /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarSitesFolderIcon.icns -button1 " Exit " -defaultButton 1
            exit 1

# if the user clicks cancel
elif [ "$?" == "2" ]; then
         echo "User canceled cache clear";   
     exit 1
fi
View original
Did this topic help you find an answer to your question?

6 replies

davidacland
Forum|alt.badge.img+18
  • Valued Contributor
  • 1811 replies
  • Answer
  • November 14, 2014

Might be a little different but I would do it this way:

USER=`who | grep console | awk '{print $1}'`

/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -title "Internet Browser Web Cache" -heading "Please exit all web pages before continuing" -alignHeading center -description "You web browser cache will be cleared when you click the button below.  This may take several minutes and you will be notified when the process completes. Thank you for your patience!" -icon /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarInfo.icns -button1 "Erase Cache" -button2 "Cancel" -defaultButton 1 -cancelButton 2

# If the user clicks Erase Cache

if [ "$?" == "0" ]; then
        echo "Clearing Cache"
        sleep 2
        rm -R /Users/$USER/Library/Caches/Google 
        rm -R /Users/$USER/Library/Caches/Firefox 
        rm -R /Users/$USER/Library/Caches/com.apple.Safari
        /Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -title "Internet Browser Web Cache" -heading "Process Complete" -alignHeading center -description "Your web browser caches have been cleared for Firefox, Safari, and Google Chrome." -icon /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarSitesFolderIcon.icns -button1 " Exit " -defaultButton 1
            exit 1

# if the user clicks cancel
elif [ "$?" == "2" ]; then
         echo "User canceled cache clear";   
     exit 1
fi

Forum|alt.badge.img+2
  • New Contributor
  • 20 replies
  • November 14, 2014

When you are defining CLEARCACHE, you have it wrapped in single quotes, instead of back ticks or $().


Forum|alt.badge.img+12
  • Author
  • Contributor
  • 150 replies
  • November 14, 2014

@davidacland, you nailed it, thanks! Can you link me to a page that describes the usage of "$?" thanks a ton for your help.

Pat


jhbush
Forum|alt.badge.img+26
  • Esteemed Contributor
  • 539 replies
  • November 14, 2014

@pat.best I made a few changes to how things were quoted and it worked for me. Thanks for posting yours as well @davidacland

#!/bin/sh

    # the purpose of this script is to delete all browser caches.
    #
    #
    # created by Pat B 11/3/14

    CLEARCACHE=$(/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -title "Internet Browser Web Cache" -heading "Please exit all web pages before continuing" -alignHeading center -description "You web browser cache will be cleared when you click the button below.  This may take several minutes and you will be notified when the process completes. Thank you for your patience" -icon /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarInfo.icns -button1 "Erase Cache" -button2 "Cancel" -defaultButton "1" -cancelButton "2")
    USER=$(who | grep console | awk '{print $1}')

    # If the user clicks Erase Cache

    if [ "$CLEARCACHE" == "0" ]; then
            echo "Clearing Cache"
            sleep 2
            rm -R "/Users/$USER/Library/Caches/Google"
            rm -R "/Users/$USER/Library/Caches/Firefox" 
            rm -R "/Users/$USER/Library/Caches/com.apple.Safari"
            /Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -title "Internet Browser Web Cache" -heading "Process Complete" -alignHeading center -description "Your web browser caches have been cleared for Firefox, Safari, and Google Chrome." -icon /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarSitesFolderIcon.icns -button1 " Exit " -defaultButton "1"
                exit 1

    # if the user clicks cancel
    elif [ "$CLEARCACHE" == "2" ]; then
             echo "User canceled cache clear";   
         exit 1
    fi

davidacland
Forum|alt.badge.img+18
  • Valued Contributor
  • 1811 replies
  • November 14, 2014

No worries! $? is basically the exit code of the last command. I normally use it in scripts to check that the last command exited as 0 (0 = good) before proceeding.

This page has some extra info: http://www.tldp.org/LDP/abs/html/exit-status.html


Forum|alt.badge.img+12
  • Author
  • Contributor
  • 150 replies
  • November 14, 2014

thanks to the both of you!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings