Apple Script Error

FRS3
New Contributor

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

1 ACCEPTED SOLUTION

sdagley
Esteemed Contributor II

@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 "")

View solution in original post

9 REPLIES 9

sdagley
Esteemed Contributor II

@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 "")

FRS3
New Contributor

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? 

sdagley
Esteemed Contributor II

@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"

FRS3
New Contributor

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.

sdagley
Esteemed Contributor II

Try:

display dialog "The new computer name entered was " & quoted form of newComputerName

FRS3
New Contributor

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.

sdagley
Esteemed Contributor II

Are you running that script in a policy triggered by on enrollment complete? You may not have a user logged in at that point.

FRS3
New Contributor

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.

sdagley
Esteemed Contributor II

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.