proof of concept examples

tlarkin
Honored Contributor

Hello Everyone,

As I mentioned during Arek's presentation, we can use JAMF Nation as a community hub to share proof of concepts on user interaction. Here go some examples I have used to give both coworkers and customers examples of how to leverage such things. This is all beginner level stuff.

example 1:

#!/bin/bash

# proof of concept AppleScript interaction to end user in bash

# declare any bash variables here

currentUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }')

##### begin user interaction #####

theAnswer=$(/usr/bin/osascript <<AppleScript
tell application "Finder"
 activate
 display dialog "Do you want to know the meaning of the universe, ${currentUser}?" buttons {"No","Yes"} default button 2
  if the button returned of the result is "No" then
   set theAnswer to No
  end if
end tell
AppleScript)

/bin/echo "${theAnswer}"

if [[ ${theAnswer} == "no" ]]

  then /bin/echo "They obviously have read the Hitcherhiker's Guide and know it is 42"
  else /bin/echo "The Answer is 42"
fi

exit 0

Here is my output of example 1 if the user clicks yes from terminal:

bash-3.2# bash -x poc_as.sh
++ /bin/ls -l /dev/console
++ /usr/bin/awk '{ print $3 }'
+ currentUser=tlarkin
++ /usr/bin/osascript
+ theAnswer=
+ /bin/echo ''


BJnKaFxM2fNFQhyKel4p

Here is the output of example 1 if the user clicks no:

bash-3.2# bash -x poc_as.sh
++ /bin/ls -l /dev/console
++ /usr/bin/awk '{ print $3 }'
+ currentUser=tlarkin
++ /usr/bin/osascript
+ theAnswer=no
+ /bin/echo no
no
+ [[ no == 
o ]]
+ /bin/echo 'They obviously have read the Hitcherhiker'''s Guide and know it is 42'
They obviously have read the Hitcherhiker's Guide and know it is 42
+ exit 0

So, as a proof of concept you could have a simple bash script invoke Applescript, and depending on if user clicks yes or no, different outputs happen. So, for example, you could have a script run once a week, or month, that prompted the end user to run a maintenance policy, software update, or whatever. If they click no, it will exit and they will be prompted again the next time it runs. If the click yes, you could then run a manual trigger policy to perform a task on the client machine.

Here is another proof of concept I have given to add asset tags to a machine record in the JSS post imaging. This could be used in a imaging work flow where your IT staff would image a machine and then post image provision it for the end user. This code could be a part of a bigger post image script, and would allow the IT staff to input the proper asset tag you stick on the physical device.

#!/bin/bash

# user apple script and bash to get input from user to update asset tags in the JSS
# by Tom Larkin
# proof of concept, no warranty given, use at own risk

# declare shell variables here, if applicable

# get usr input from Apple Script and try to redirect output back into bash and user recon to update the JSS

/usr/bin/osascript <<-AppleScript

tell application "Finder"
    activate
    display dialog "Enter your asset number" default answer "Enter your asset tag number here"
    set theAnswer to (text returned of result)
    set cmd to "/usr/sbin/jamf recon -assetTag " & theAnswer
    do shell script cmd
end tell

AppleScript


exit 0

Here is the output from terminal:

bash-3.2# bash -x asset 2.sh
+ /usr/bin/osascript
 (1) This application must be run as root. Try the sudo command.
+ exit 0

Since the JAMF binary requires sudo rights to execute the recon command it failed, but when ran by the JAMF framework you wouldn't get those results. Which is a good thing because I would have changed my asset tag in our JSS to "1234." So, this is also a great example of being mindful of what you are allowing users to do. Best practices will vary from organization to organization.

These are simple examples that could get you started down the path of custom building user interactions with your end users. These examples are a good point to start at, and expand upon after you gain more skills in your overall skill set. Of course a lot of this depends on your preferred work flows, culture, and policies of your organization so there is never a one-szie-fits-all solution we can post here.

Hopefully, more examples will come from this. Thanks to everyone who came out and a big thanks to Arek for sharing his really cool solutions he has developed and leveraged with the Casper Framework.

Thanks,
Tom

7 REPLIES 7

tlarkin
Honored Contributor

Here is a JAMF Helper example I have used in presentations as a proof of concept.

#!/bin/bash

/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType hud -description "JNUC 2013!!!!" -icon /Library/Desktop Pictures/lake.jpg &

/bin/sleep 5

/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -kill

exit 0

In this example, we are using the ampersand (&) to background the JAMF Helper process. This way we can display a HUD notification to the end user while you execute policies by manual triggers from a script. You could use this script as a proof of concept to start the process, then run your manual triggers. When it is all said and done you would kill the JAMF helper process so the dialog box disappears.

mikeh
Contributor II

Thanks Tom! I was wondering how you could programmatically dismiss a jamfHelper window!

khowe
New Contributor II

Thanks Tom. Hopefully Arek will post his slides and examples somewhere as well. There were a couple useful ones I would like to play with.

bentoms
Release Candidate Programs Tester

@khowe here's one example of interacting with end users to get them to change the screen shot locations via Self Service

http://macmule.com/2013/07/13/change-screenshot-location-from-self-service-with-gui-prompt/

tkimpton
Valued Contributor II

Been doing that already for nearly 2 years now. Will post an example tomorrow.

tkimpton
Valued Contributor II

Reset Firefox example i use in Self Service

#!/bin/bash

user=`ls -l /dev/console | cut -d " " -f4`

# Show the Desktop through Expose
/Applications/Utilities/Expose.app/Contents/MacOS/Expose 1

# Displaying a message to tell the user to wait

x=`/usr/bin/osascript <<EOT
tell application "Finder"
        activate
        set myReply to button returned of (display dialog "Please wait for the script to do its stuff and wait for confirmation! When the restore is complete, select Don't import anything, click Continue and within Firefox click Bookmarks > Show All Bookmarks > Click star symbol > Restore > browse to the backup" buttons {"Cancel" , "Do it!"} default button "Cancel")
end tell
EOT`
echo 'Button is: '$x
if [[ $x = "Do it!" ]]; then
echo 'Shell script continues...'

#osascript -e 'tell app "System Events" to display dialog "Please wait for the script to do its stuff and wait for confirmation!" buttons {"Cancel" , "Do it!"} default button "Cancel"'

# quitting Firefox
killall -9 firefox-bin
killall -9 firefox

# Removing previous Firefox_bookmarkbackups as the currently logged in user
su - "${user}" -c 'rm -rf ~/Documents/Firefox_bookmarkbackups'

# Pausing 3 seconds
sleep 3

# Making a backup directory as the currently logged in user
su - "${user}" -c 'mkdir ~/Documents/Firefox_bookmarkbackups'

# Making a temp directory as the currently logged in user
su - "${user}" -c 'mkdir ~/Temp'

# Pausing 3 seconds
sleep 3

# Find the users bookmarkbackups and move them to the temp directory as the currently logged in user
su - "${user}" -c 'Find -x ~/Library/Application Support/Firefox/Profiles/********.default/ -name 'bookmarkbackups' -print0 | xargs -0 -I bookmarkbackups cp -R bookmarkbackups ~/Temp/'

# Pausing 3 seconds
sleep 3

# Copy the bookmarkbackups to the Firefox_bookmarkbackups directory as the currently logged in user
su - "${user}" -c 'cp -R ~/Temp/bookmarkbackups ~/Documents/Firefox_bookmarkbackups/'

# Pausing 5 seconds
sleep 5

# Deleting the FireFox app data as the currently logged in user
su - "${user}" -c 'rm -rf ~/Library/Application Support/Firefox'

# Removing the users Firefox cache as the currently logged in user
su - "${user}" -c 'rm -rf ~/Library/Caches/Firefox'

# Pausing 5 seconds
sleep 5

# Launch Firefox as the currently logged in user 
su - "${user}" -c 'open /Applications/Firefox.app'

# Pausing 10 seconds
sleep 10

# Moving the bookmarkbackups from the temp to the users new app data location as the currently logged in user
su - "${user}" -c 'Find -x ~/Library/Application Support/Firefox/Profiles/ -name '********.default' -print0 | xargs -0 -I folder mv ~/Temp/bookmarkbackups/ folder'

# Pausing 3 seconds
sleep 3

# Removing the Temp directory as the currently logged in user
su - "${user}" -c 'rm -rf ~/Temp'

# Launch Firefox as the currently logged in user
su - "${user}" -c 'open http://kb.mozillazine.org/Lost_bookmarks#Restoring_bookmarks_in_Firefox_3_and_above /Applications/Firefox.app'

# Show the Desktop through Expose
/Applications/Utilities/Expose.app/Contents/MacOS/Expose 1

# Display dialog to tell the user to look at the Restoring bookmark backups section
osascript -e 'tell app "System Events" to display dialog "Restore Complete. Click Bookmarks > Show All Bookmarks > Click star symbol > Restore > browse to the backup"'
fi

tkimpton
Valued Contributor II

other key to it is to bring back Expose ;)

#!/bin/bash

### Check to see if Expose exists!
if ls /Applications/Utilities/Expose.app/
then 

### Just echo to the console
echo "Already exists"
else

### Otherwise make the Symblic links
ln -sf /Applications/Mission Control.app/ /Applications/Utilities/Expose.app
ln -sf /Applications/Mission Control.app/Contents/MacOS/Mission Control /Applications/Mission Control.app/Contents/MacOS/Expose
fi