Skip to main content
Solved

AppleScript Error - No user interaction allowed


Forum|alt.badge.img+4

I do a policy that will run script for user to shutdown/restart their laptop if the uptime is more than 7days.
The script is like this:

set question to display dialog "The machine has not been shut down or restarted for more than a week. Please shut down or restart the machine by clicking on Shut Down or Restart." with title "System Event by Andres Cheah, MCM" with icon stop buttons {"Shut Down", "Restart", "Cancel"}
set answer to button returned of question
if answer is equal to "Shut Down" then tell application "System Events" shut down end tell
end if
if answer is equal to "Restart" then tell application "System Events" restart end tell
end if
if answer is equal to "Cancel" then return
end if

I test in the machine it is working fine, but when i put into the policy; there an error below:

Script exit code: 1
Script result: 2013-09-23 10:15:47.576 osascript[2866:707] ApplePersistence=NO /Library/Application Support/JAMF/tmp/System event-AppleScript Applet.scpt: execution error: No user interaction allowed. (-1713)

Anyone can advise?

Best answer by aurica

Give this a try:

#!/bin/bash
VARIABLE=$(/usr/bin/osascript <<-EOF
tell application "System Events"
    activate
    set question to display dialog "The machine has not been shut down or restarted for more than a week. Please shut down or restart the machine by clicking on Shut Down or Restart." with title "System Event by Andres Cheah, MCM" buttons {"Shut Down", "Restart", "Cancel"} with icon caution
    set answer to button returned of question
    if answer is equal to "Shut Down" then
        tell application "System Events"
            shut down
        end tell
    end if
    if answer is equal to "Restart" then
        tell application "System Events"
            restart
        end tell
    end if
    if answer is equal to "Cancel" then
        return
    end if
end tell
EOF)

$VARIABLE
exit 0
View original
Did this topic help you find an answer to your question?

14 replies

bentoms
Forum|alt.badge.img+35
  • Legendary Contributor
  • 4331 replies
  • September 23, 2013

It's because Casper runs as root & not the logged in user.

Try wrapping it in a tell block..

Like "tell Finder..... end tell"


bentoms
Forum|alt.badge.img+35
  • Legendary Contributor
  • 4331 replies
  • September 23, 2013

Also, I've had luck when using AppleScript from Bash scripts... Like: http://macmule.com/2013/07/13/change-screenshot-location-from-self-service-with-gui-prompt/#more-595


Forum|alt.badge.img+4
  • Author
  • Contributor
  • 12 replies
  • September 23, 2013

hi, thanks for the reply,

i already put "end tell" , same error..


Forum|alt.badge.img+14
  • Valued Contributor
  • 296 replies
  • September 23, 2013

I had a similar problem having to run a script to prompt to change AD passwords so what I did was store the script on every system within a directory that you know exists on all macs. I used the /Users/Shared directory and then I used this script to call it to run and to make it run as the user logged in and not root:

#!/bin/bash

user=/usr/bin/last -1 -t console | awk '{print $1}'
su -l $user -c "open /Users/Shared/filenamecontainingscript"

I also used an applescript as the stored script in the /Users/Shared folder. Hope this helps.


Forum|alt.badge.img+16
  • Contributor
  • 15 replies
  • Answer
  • September 23, 2013

Give this a try:

#!/bin/bash
VARIABLE=$(/usr/bin/osascript <<-EOF
tell application "System Events"
    activate
    set question to display dialog "The machine has not been shut down or restarted for more than a week. Please shut down or restart the machine by clicking on Shut Down or Restart." with title "System Event by Andres Cheah, MCM" buttons {"Shut Down", "Restart", "Cancel"} with icon caution
    set answer to button returned of question
    if answer is equal to "Shut Down" then
        tell application "System Events"
            shut down
        end tell
    end if
    if answer is equal to "Restart" then
        tell application "System Events"
            restart
        end tell
    end if
    if answer is equal to "Cancel" then
        return
    end if
end tell
EOF)

$VARIABLE
exit 0

Forum|alt.badge.img+4
  • Author
  • Contributor
  • 12 replies
  • September 24, 2013

Hi aurica,

I try the script, work fine. But when upload it and run using Casper, this error:

Executing Policy Never Shutdown 7days...
Mounting my-jss01 to /Volumes/CasperShare...
Running script SystemEvent.sh...
Script exit code: 0
Script result: 449:453: syntax error: Expected end of line but found application constant or consideration. (-2741)


Forum|alt.badge.img+16
  • Contributor
  • 15 replies
  • September 24, 2013

I had success with my sample. I uploaded it into my 8.62 environment as pairjal_test.sh and set up a manually triggered policy.

Log from user cancelation, which registers as a policy failure:

/usr/sbin/jamf is version 8.62
Executing Policy pairjal test...
Creating directory structure for /Library/Application Support/JAMF/Downloads/
Downloading http://FQDN:80/ShareName/Scripts/pairjal_test.sh...
Running script pairjal_test.sh...
Script exit code: 0
Script result: 58:329: execution error: System Events got an error: User canceled. (-128)

Log from successful restart and shutdown:

/usr/sbin/jamf is version 8.62
Executing Policy pairjal test...
Creating directory structure for /Library/Application Support/JAMF/Downloads/
Downloading http://FQDN:80/ShareName/Scripts/pairjal_test.sh...
Running script pairjal_test.sh...
Script exit code: 0
Script result:

The syntax error in your last post makes me suspect that you might have dropped a ( in the copy/paste?


Forum|alt.badge.img+31
  • Honored Contributor
  • 2721 replies
  • September 24, 2013

Hey Everyone,

I had this problem moving forward with 10.7 and 10.8. Where the Applescript, when ran as root, did not like not having a user environment. To get around this, I would save my scripts as apps in Applescript then use the `sudo -u` command to run as root as the current user.

So, I would toss my Applescript app in the Scripts folder on my CasperShare, then have another script call it like this:

#!/bin/bash

# execute applescript as end user
currentUser=$(ls -l /dev/console | awk '{ print $3 }')

sudo -u ${currentUser} open /Volumes/CasperShare/Scripts/myapplescript.app

exit 0

The CasperShare will always mount to /Volumes, and I just had scripts call the app from there with the open command.

I hope this may help you out.

Tom


Forum|alt.badge.img+1
  • New Contributor
  • 2 replies
  • September 25, 2013

+1


Forum|alt.badge.img+4
  • Author
  • Contributor
  • 12 replies
  • September 25, 2013

Hi Aurica

thanks for the script. i have modified and working fine now.


Forum|alt.badge.img+6
  • Contributor
  • 15 replies
  • December 31, 2013

For me, "tell application "System Events"" does not work, however tell application "Finder" does.


Forum|alt.badge.img+6
  • Contributor
  • 15 replies
  • February 27, 2014

Issue seems to be resolved with 9.24


Forum|alt.badge.img+3

So, you can now launch that applescript from a bash script? Im trying to make this happen and its just not going.


AVmcclint
Forum|alt.badge.img+21
  • Esteemed Contributor
  • 1043 replies
  • April 6, 2015

I would love to use a script like this. However, I can't figure out how to set the threshold for when to trigger it to happen. I'd like for our computers to be rebooted if their uptime is greater than 20 days. And if a user clicks cancel, how much time can elapse before it is triggered again?


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings