Apple script and shell execution using the logged-in user context

New Contributor

I have a small question about the user migration script that doesn't interact correctly with the session
I did the test with a very simple script and it is the same problem: it behaves differently depending if it is run on the machine or executed via JAMF (remote, script execution)
When I run it locally I have the expected effect "a dialog box that launches, we enter a string and this string is written in a file".
On the other hand, via Jamf Remote, when launching the script on a remote computer I already see nothing on the target computer session and I have these logs :

Running script testscrp... Script exit code: 0 Script result: 33:41: execution error: Une erreur de type -10810 est survenue. (-10810) 33:41: execution error: Erreur dans System Events : Application is not oppened. (-600) Finished.

I haven't found a way, even by "calling" the application or acting in a "user" context...yet as soon as you launch it live, the script runs fine
Including retrieving the session id and adding a

Set $3 do do Shell script

I didn't succeed...
I search if Jamf Nation offers alternatives like storing and calling the script via

sudo -u ${currentuser}

but it's the same problem...
Maybe i've missed something..

Here is my test script:

# test

#get First Attempt
result=`/usr/bin/osascript <<EOT
tell application "System Events"
set myReply to text returned of (display dialog "test hidden string here…" ¬
default answer "" ¬
buttons {"Cancel","Continue"} ¬
default button 2 ¬
with hidden answer)
end tell

echo $result >> /tmp/test.txt

Thanks for your help