"Osascript is trying to send restricted scripting addition commands to other applications..."

Have you tried running your AppleScript from the Script Editor?

If so, and you get the same message, please upload your script in a Code Block.