OSAScript Errors

josh_fischer
New Contributor

Hi All, hoping for some help here. Looking to frankenstein together a script to add our admin account to FV2 as an enabled user. I've got a script that is currently working under the following conditions:

Running locally in terminal
Running manually from Self Service

It is not working when running automatically via JAMF policy. That is my goal at this point.

The script is here:

!/bin/sh

Add ADMIN ACCOUNT to FV2.sh

userName=$(/usr/bin/stat -f%Su /dev/console)
prefix='SECRET HERE'
pass=$prefix

Get the logged in user's password via a prompt

echo "Prompting ${userName} for their login password."
userPass="$(/usr/bin/osascript -e 'Tell current application to display dialog "Please enter your login password:" default answer "" with title "ADMIN ACCOUNT FileVault 2 Key Escrow" with text buttons {"Ok"} default button 1 with hidden answer' -e 'text returned of result')"

echo "Adding ADMIN ACCOUNT to FileVault"

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 ADMIN ACCOUNT
expect "Enter the user name:"
send "${userName}"
expect "Enter the password for user '${userName}':"
send "${userPass}"
expect "Enter the password for the added user 'ADMIN ACCOUNT':"
send "${pass}"
log_user 1
expect eof
"
expect -c "
log_user 0
spawn fdesetup changerecovery -personal
expect "Enter the user name:"
send "${userName}"
expect "Enter the password for user '${userName}':"
send "${userPass}"
log_user 1
expect eof
"

exit 0

The error that is being thrown in JAMF is here:

Script result: Prompting joshfischer for their login password.
2020-08-12 12:10:24.539 osascript[10912:277821] -[NSCFConstantString objectAtIndex:]: unrecognized selector sent to instance 0x7fff9153d0e0
2020-08-12 12:10:24.544 osascript[10912:277821]
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFConstantString objectAtIndex:]: unrecognized selector sent to instance 0x7fff9153d0e0'
First throw call stack:
( 0 CoreFoundation 0x00007fff39d0ab57 exceptionPreprocess 250 1 libobjc.A.dylib 0x00007fff729b85bf objc_exception_throw 48 2 CoreFoundation 0x00007fff39d89be7 -[NSObject(NSObject) _retain_OA] 0 3 CoreFoundation 0x00007fff39c6f3bb ___forwarding 1427 4 CoreFoundation 0x00007fff39c6ed98 CF_forwarding_prep_0 120 5 CoreFoundation 0x00007fff39c3ded7 CFArrayContainsValue 197 6 HIServices 0x00007fff37f447b9 TransformProcessType 927 7 osascript 0x000000010e1ef02c osascript 12332 8 HIToolbox 0x00007fff389597c5 AEInteractWithUser 53 9 StandardAdditions 0x00000001126838b9 CSDSTEXTurl 5865 10 StandardAdditions 0x0000000112674331 AEVTsysodlog 85 11 AE 0x00007fff3b001203 _AppleEventsCheckInAppWithBlock 18103 12 AE 0x00007fff3b010c83 AESendMessage 2838 13 AE 0x00007fff3b01cfb1 aeSend 355 14 osascript 0x000000010e1edb25 osascript 6949 15 AppleScript 0x00007fff4d99d342 _Z13ComponentSendPK6AEDescPS_ii 485 16 AppleScript 0x00007fff4d9aef0a _ZN15TUASApplication4SendEP25TStackFrame_UASRemoteSendP6AEDescS3_hhh 2332 17 AppleScript 0x00007fff4d9cfca7 _Z13UASRemoteSendhhhhhPh 548 18 AppleScript 0x00007fff4d9db402 _Z13UASValue_Sendhh14TUASClassIndexh 326 19 AppleScript 0x00007fff4d9b2ff9 _Z11UASExecute1v 288 20 AppleScript 0x00007fff4d986b26 _Z14ASExecuteEventPK6AEDescjiPj 614 21 AppleScript 0x00007fff4d97f971 AppleScriptComponent 1677 22 AppleScript 0x00007fff4d998bdb _ZN12AGenericCall8DelegateEP23ComponentInstanceRecord 37 23 AppleScript 0x00007fff4d998ba1 _ZN15AGenericManager13HandleOSACallEP19ComponentParameters 57 24 AppleScript 0x00007fff4d99818c GenericComponent 156 25 OpenScripting 0x00007fff38b9c3e2 OSAExecuteEvent 50 26 osascript 0x000000010e1ee5bd osascript 9661 27 libdyld.dylib 0x00007fff73b60cc9 start 1 28 ??? 0x0000000000000005 0x0 5
)
libc
+abi.dylib: terminating with uncaught exception of type NSException

I have a PPPC for OSA Script applied and for Terminal. Unsure where to go from here....please help!

1 ACCEPTED SOLUTION

josh_fischer
New Contributor

I seem to have found an answer with the help of a colleague...changing userPass="$(/usr/bin/osascript -e 'Tell current application to display dialog "Please enter your login password:" default answer "" with title "ADMIN ACCOUNT FileVault 2 Key Escrow" with text buttons {"Ok"} default button 1 with hidden answer' -e 'text returned of result')" to userPass="$(/usr/bin/osascript -e 'Tell application "system events" to display dialog "Please enter your login password:" default answer "" with title "ADMIN ACCOUNT FileVault 2 Key Escrow" with text buttons {"Ok"} default button 1 with hidden answer' -e 'text returned of result')" seems to have worked

View solution in original post

1 REPLY 1

josh_fischer
New Contributor

I seem to have found an answer with the help of a colleague...changing userPass="$(/usr/bin/osascript -e 'Tell current application to display dialog "Please enter your login password:" default answer "" with title "ADMIN ACCOUNT FileVault 2 Key Escrow" with text buttons {"Ok"} default button 1 with hidden answer' -e 'text returned of result')" to userPass="$(/usr/bin/osascript -e 'Tell application "system events" to display dialog "Please enter your login password:" default answer "" with title "ADMIN ACCOUNT FileVault 2 Key Escrow" with text buttons {"Ok"} default button 1 with hidden answer' -e 'text returned of result')" seems to have worked

View solution in original post