Hello I need some help with some dialog boxes

sebastian_santo
New Contributor III

I need my users to enter their username and job title and I have tried using osascript for this to call an AppleScript but I push it to Machine been provisioned in Singapore or Australia the dialog box never comes up any help will be appreciated. please see error bellow

Running script Gatherusecominfo...
Script exit code: 0
Script result: 2020-05-01 07:17:33.577 osascript[3063:22256] -[_NSCFConstantString objectAtIndex:]: unrecognized selector sent to instance 0x7fff89134ce0
2020-05-01 07:17:33.581 osascript[3063:22256]
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFConstantString objectAtIndex:]: unrecognized selector sent to instance 0x7fff89134ce0'
First throw call stack:
(
0 CoreFoundation 0x00007fff3162bd07 exceptionPreprocess 250
1 libobjc.A.dylib 0x00007fff6a1b65bf objc_exception_throw
48
2 CoreFoundation 0x00007fff316aac97 -[NSObject(NSObject) __retain_OA] 0
3 CoreFoundation 0x00007fff3159057b ___forwarding
1427
4 CoreFoundation 0x00007fff3158ff58 CF_forwarding_prep_0 120
5 CoreFoundation 0x00007fff3155f097 CFArrayContainsValue
197
6 HIServices 0x00007fff2f8717b9 TransformProcessType 927
7 osascript 0x0000000106d4b02c osascript
12332
8 HIToolbox 0x00007fff302817c5 AEInteractWithUser 53
9 StandardAdditions 0x00000001076b310b AEVTgtqpchlt
159
10 AE 0x00007fff32922203 _AppleEventsCheckInAppWithBlock 18103
11 AE 0x00007fff32931c83 AESendMessage
2838
12 AE 0x00007fff3293dfb1 aeSend 355
13 osascript 0x0000000106d49b25 osascript
6949
14 AppleScript 0x00007fff45283342 _Z13ComponentSendPK6AEDescPS_ii 485
15 AppleScript 0x00007fff45294f0a _ZN15TUASApplication4SendEP25TStackFrame_UASRemoteSendP6AEDescS3_hhh
2332
16 AppleScript 0x00007fff452b5ca7 _Z13UASRemoteSendhhhhhPh 548
17 AppleScript 0x00007fff4528e1f0 _Z13UASActor_Sendhhh
383
18 AppleScript 0x00007fff452c1402 _Z13UASValue_Sendhh14TUASClassIndexh 326
19 AppleScript 0x00007fff45298ff9 _Z11UASExecute1v
288
*

6 REPLIES 6

arivera
New Contributor III

Can you show the script ? And also what operating system are these computers running ?

sebastian_santo
New Contributor III

@arivera

!/bin/sh

#################################################################################################################

This script was create to update computer information on jamf more specific to Users & Location tab in the jamf pro server

Created by Sebastian Santos on Apr/28/2020. #

#################################################################################################################

This sets the enduser department

Department=`/bin/launchctl asuser 0 /usr/bin/osascript <<EOT
set Department to {"C-Suite", "Engineering", "Finance", "Human Resources", "IT", "Legal", "Marketing", "Professional Services", "Sales", "Sales Engineering", "Tech Support", "N/A"}
set Department to (choose from list Department with prompt "Please select user department:")
set Department to the result

EOT`
echo "$Department"

This sets the enduser building and location as region

Building=`/bin/launchctl asuser 0 /usr/bin/osascript <<EOT
set Building to {"Austin Texas - North America", "American Fork - North America", "Baltimore Maryland - North America", "Boston - CEC - North America", "Champaign - North America", "Herndon - North America", "New York City - North America", "Richardson - North America", "Salt Lake City - North America", "St. Paul - North America", "San Diego - North America", "Remote - North America", "Beijing - APAC", "Sydney - APAC", "Singapore - APAC", "Remote - APAC", "Dublin - EMEA", "Helsinki - EMEA", "Israel Tel Aviv - EMEA", "Krakow - EMEA", "Ra'anana - EMEA", "Ramat Gan - EMEA", "Reading - EMEA", "Remote - EMEA"}
set Building to (choose from list Building with prompt "Please select the State that best describes your building or location:")
set Building to the result

EOT`

echo "$building"

Enduser information

EndUsername=`/bin/launchctl asuser 0 /usr/bin/osascript <<EOT
display dialog "Please enter username here:" default answer "i.e. john.doe or jdoe"
set EndUsername to text returned of the result

EOT`

echo "$EndUsername"

Here we will ask for the enduser position and or bussines role

Position_role=`/bin/launchctl asuser 0 /usr/bin/osascript <<EOT
display dialog "Please enter user position here:" default answer ""
set Position_role to text returned of the result

EOT`

echo "$Position_role"
and OS is Catalina and Mojave

arivera
New Contributor III

Have you PPPC whitelisted osascript via a configuration profile? Also if you do not have a very helpful piece of software for writing and testing scripts on the go, take a look at CodeRunner. But I also think there are some errors in your script, I am checking right now.

arivera
New Contributor III

Here's an example of an old script I made for a popup like what you are looking for. This is just a snippet, whatever you end up doing with the results, then thats up to you. Give it a try and maybe you can integrate or use this for your own script I'm sure.

@sebastian.santos Just remember to create a PPPC profile to whitelist osascript for System Events, etc.

#!/bin/sh
loggedInUser=$(stat -f%Su /dev/console)
loggedInUID=$(id -u $loggedInUser)

department=$(/bin/launchctl asuser $loggedInUID sudo -iu $loggedInUser << EOF
/usr/bin/osascript -e 'tell application "System Events"
activate
choose from list {"Sales - Business Development", "Sales - Solutions Consulting", "Sales - Revenue Operations", "Marketing", "CS - Customer Support", "CS - Client Success", "CS - Client Education", "CS - Implementation", "CS - Creative", "Operations - Finance", "Operations - Human Resources", "Product - Product Management", "Product - Product Design", "Engineering - QA", "Engineering - Data Science", "Engineering - Software Engineering", "Engineering - DevOps"} with title "My Company Name" with prompt "Please Select Your Department"
end tell' 2>/dev/null
EOF)

echo $department

sebastian_santo
New Contributor III

@arivera I have whitelisted osascript for system events also the terminal but I always get a pop-up window saying loginwindow wants access to control system events

I will give your script a try thank you so much

leslie
Contributor II

As @arivera illustrates it you'll need to launch the process in the user space, not root, or the following will not be displayed to the logged in user:

display dialog "Please enter username here:" default answer "i.e. john.doe or jdoe"

Also, in case you didn't notice echo "$building" should be echo "$Building"