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