Interactive scripts

luke_reagor
Contributor II

Is there a way to make a script (shell or applescript, or maybe even something else) visible and interactive when it's ran via a policy in self service?

3 REPLIES 3

Snickasaurus
Contributor

What are you looking to accomplish with this script?

The below is PART of a larger script that I use to ask the current logged in user for their password so I can enable their Filevault 2 account. It runs from Self Service and opens an Applescript dialog.

## Get the logged in user's password via a prompt
echo "Prompting ${userName} for their login password."
userPass="$(/usr/bin/osascript -e 'Tell application "System Events" to display dialog "Credentials" default answer "" with title "Login Password" with text buttons {"Ok"} default button 1 with hidden answer' -e 'text returned of result')"

echo "Issuing new recovery key"

if [[ $OS -ge 9  ]]; then
    ## This "expect" block will populate answers for the fdesetup prompts that normally occur while hiding them from output
    expect -c "
    log_user 0
    spawn fdesetup add -usertoadd $(userName)
    expect "Enter a password for '/':"
    send ""
    expect "Enter the password for the added user '"${userName}"':"
    send "${userPass}"
    log_user 1
    expect eof
    "
else
    echo "OS version not 10.9+ or OS version unrecognized"
    echo "$(/usr/bin/sw_vers -productVersion)"
    exit 5
fi

luke_reagor
Contributor II

How do you make the script visible so they can see the echo and respond? Can they only respond to the AppleScript?

Here's an example:

!/bin/bash

echo -n "What is your name? " && read theName
echo "Hello, $theName."

luke_reagor
Contributor II

Thanks for the tip on applescript. I ended up using the applescript format that @Look mentioned in this article:
https://jamfnation.jamfsoftware.com/discussion.html?id=15225