Initiate Chat Script via Casper Remote

agetz
Contributor

We have been moving away from Apple Remote Desktop in recent years and have been trying to use Casper Remote more often. We got to a point where we were only using ARD for its chat feature. I worked up a script that can be run from Casper Remote that prompts the end user to see if they are available for remote support, then if they agree, it opens a pre-filled text document with TextEdit. This document auto-saves in the users documents folder. Hopefully this is useful to someone else. Also if anyone sees room for improvement, please comment. Thanks.

#!/bin/bash
#Aaron Getz

# We capture the logged in user and the UID to use later when running the local script as the user
loggedInUser=$(stat -f%Su /dev/console)
loggedInUID=$(id -u "$loggedInUser")

# Create a script in /tmp to run as the logged in user
cat << EOS > /private/tmp/availability_user.sh
#!/bin/bash

#Sound to Alert User
afplay /System/Library/Sounds/Basso.aiff

# Run an Applescript to Prompt the User for Availability
Availability=$(/usr/bin/osascript << EOD
tell app "System Events"
activate
set myMsg to "Message from Technology: We received your recent tech request. Are you available for remote support?"
   set theResp to display dialog myMsg buttons {"No", "Yes"} default button 2 
end tell
EOD)

# Echo back the selection result
echo "$Availability"

EOS

# Script creation done

# Now make the new script executable
chmod +x /private/tmp/availability_user.sh

# Run the script as the user, capturing the output into a new variable
AvailabilityResponse=$(/bin/launchctl asuser "$loggedInUID" sudo -iu "$loggedInUser" "/private/tmp/availability_user.sh")

# If the button returned from the confirmation was Yes, then create and open the file
if [ "$AvailabilityResponse" == "button returned:Yes" ]; then
    echo "User available. Starting chat..."

# Create a text file in Logged in Users Documents
cat << EOS > /Users/$loggedInUser/Documents/Tech_Chat_Log.txt

Hello, I will be taking care of your issue today. Please give me a moment to get connected.



EOS

# File creation done

# Now make the new file editable.
chmod 777 /Users/$loggedInUser/Documents/Tech_Chat_Log.txt

# Now open the new file.

/bin/launchctl asuser "$loggedInUID" sudo -iu "$loggedInUser" open -e /Users/$loggedInUser/Documents/Tech_Chat_Log.txt

exit 0
else
    # If not, cancel since the user chose No
    echo "User is not available."
    exit 0
fi
0 REPLIES 0