Posted on 07-18-2023 02:12 PM
Hello everyone - I have created an interactive Apple Script that prompts a user to input their username and it works w/o issue in terminal, but when I have it in Self Service the GUI doesn't come up unless I hit cancel, but it still works which is a plus, but I rather it work like it should and not be a happy little accident.
Also this same script when setting it to run after enrollment completes I get an error of "Script result: 95:158: execution error: No user interaction allowed. (-1713)" Which I believe is because the script is being ran as root?
Here is the script in its entirety. I appreciate you all.
#!/bin/bash
# Prompt the user to enter the new computer name
IFS= read -r -p "Enter the new computer name using department abbreviation and asset tag (Ex:DEPT-123456): " newComputerName
# Execute the AppleScript using osascript
osascript <<-EOF
-- Prompt the user to enter the new computer name
set newComputerName to text returned of (display dialog "Enter the new computer name:" default answer "")
-- Define the shell script commands
set setComputerName to "sudo scutil --set ComputerName " & quoted form of newComputerName
set setLocalHostName to "sudo scutil --set LocalHostName " & quoted form of newComputerName
set setHostName to "sudo scutil --set HostName " & quoted form of newComputerName
-- Execute the shell script commands using osascript and administrator privileges
do shell script setComputerName with administrator privileges
do shell script setLocalHostName with administrator privileges
do shell script setHostName with administrator privileges
EOF
Solved! Go to Solution.
Posted on 07-18-2023 07:20 PM
@FRS3 Remove the following line in your script:
IFS= read -r -p "Enter the new computer name using department abbreviation and asset tag (Ex:DEPT-123456): " newComputerName
It's trying to display a shell prompt for the user to enter the computer name, and that will not work when running via Jamf Pro. It's also redundant because the following line is doing the same prompt via AppleScript:
set newComputerName to text returned of (display dialog "Enter the new computer name:" default answer "")
Posted on 07-18-2023 07:20 PM
@FRS3 Remove the following line in your script:
IFS= read -r -p "Enter the new computer name using department abbreviation and asset tag (Ex:DEPT-123456): " newComputerName
It's trying to display a shell prompt for the user to enter the computer name, and that will not work when running via Jamf Pro. It's also redundant because the following line is doing the same prompt via AppleScript:
set newComputerName to text returned of (display dialog "Enter the new computer name:" default answer "")
Posted on 07-19-2023 07:06 AM
Thank you so much for this @sdagley. Is there any easy way to have the new name that the end user input echoed back to them afterwards?
Posted on 07-19-2023 07:18 AM
@FRS3 I'm not completely sure of the syntax but I think this will display the text entered at the computer name prompt:
display dialog "The new computer name entered was $newComputerName"
Posted on 07-19-2023 07:36 AM
I had tried that earlier and get back "the new computer name entered was". For whatever reason it's not seeing $newComputerName value and spitting it back out.
Posted on 07-19-2023 07:46 AM
Try:
display dialog "The new computer name entered was " & quoted form of newComputerName
Posted on 07-19-2023 08:22 AM
Yup that worked for me. Appreciate all the help. Self Service runs perfectly. Now to figure out why I keep getting Script result: 95:215: execution error: No user interaction allowed. (-1713) when having that script run after enrollment.
Posted on 07-19-2023 08:26 AM
Are you running that script in a policy triggered by on enrollment complete? You may not have a user logged in at that point.
Posted on 07-19-2023 08:29 AM
Yes, I thought maybe since Jamf Connect runs and I log in it would do it after that, but reading around sounds like the script runs before I even have the chance to login.
Posted on 07-19-2023 09:06 AM
It's not the latest & coolest technology, but I'd suggest you take a look at the combination of DEPNotify and DEPNotify-Starter to run any policies you want to have triggered on enrollment.