I need help with force restart script and one other thing

I’ll start with what I am trying to do and why. I have a number of Macs that are “public” systems. The policy where I am located is that the systems be set to “Require password after sleep or screen saver begins”. The problem is that, as you might expect, a user logs in to the system, performs their task and walks away. 15 minutes later, the screen saver kicks in and the screen locks and the next user can not get on the system. The simple solution to set the system to “Log out after “15” minutes of inactivity” does not work because one of the applications that is usually opened by the users is Citrix; Which cancels the log out because it wants confirmation of the disconnection.

So, what I am trying to do is come up with a script and/or Automator app that will run after 15 minutes of inactivity. It is a simple matter to write an Automator workflow that will “Quit All Applications” (with Ask to save changes Unchecked - Which still won’t overcome the “Confirm Disconnect” dialog box in Citrix) and then “Run AppleScript” with the following script:

tell application “System Events”
restart
end tell

               Sidebar question about this simple script: I tried the script like this:

tell application “System Events”
force restart
end tell

And although it compiles without any errors, when I tried to run it I get the following error:

error “The variable force is not defined.” number -2753 from “force”

So, is there a different “Force Restart” command I could tell System Events to run?

And then on to what seems to be the biggest obstacle. Provided that I have a proper Automator app written that will quit all running apps AND force the system to restart (or alternately force the system to Log Out of the current user), how can I tell the system to launch that app after 15 minutes of inactivity?

I have also looked in to the possibility of using this command in Terminal:

reboot -q

and save it as an executable shell script (but I can not seem to figure out how to MAKE an executable shell script) and then using the screensaver that other folks have mentioned called ScriptSaver. If I could get the right script to force a reboot, would that work?

Any help would be very much appreciated.

thanks

Your error message.

Is because, System Events does not have a force quit command, and so it thinks your trying to declare
a variable called force.

The only four power suite commands that are valid with System Events are.

log out
restart
shut down
sleep

So sorry, but no force quit command.

As for running an Applescript every 15 minutes, thats possible with an on idle handler, in a saved stay open applet.

Like this.

[code]on run
–put any startup code in here
end run

on idle
–put any code in here that you want to run every 15 minutes
return (15 * minutes) --set the idle handler to run every 15 minutes
end idle

on quit
–put any shut down code in here
continue quit
end quit[/code]
As for checking for inactivity, there might be a way of checking if the screen saver is running, as System Events
does have some screen saver commands, but I am not sure how you would check for a running screen saver.
But some other forum member might be able to help with that.

Not much help, but some useful info for you anyway.

Regards Mark

Thanks for the information Mark. How about this: Is there a way take this UNIX command:

shutdown -r now

and wrap it in to an AppleScript?

after some experimentation, what I really need is an AppleScript that will run as super user (without any intervention) and will, first, force quit all running applications (without saving changes), then, second run the command:

shutdown -r now

Is there a way to create such a script?

do shell script “shutdown -r now” with administrator privileges

I’m not behind a mac right now

do shell script "killall Citrix"

Does this not work without user interaction?

BJ Bazzie Wazzie, I am a real novice with scripting. Can you send me instructions on how to create that script with the username and password embedded in it?

Alastor993, killall Citrix would quit citrix, but I also need to force a reboot while logged on as a non-administrator

“do shell script” is in Standard Additions. Read its dictionary: cmd-shift-L in AppleScript Editor,
then double-click Standard Additions in the window that appears. This should always be your first port of call…

set username to "UsernameWithAdminPrivileges"
set passwd to "Password4username"

do shell script "shutdown -r now" user name username password passwd with administrator privileges

DJ, I put the script you posted in to AppleScript Editor just like this:

set username to “censoreduser”
set passwd to “censoredpw”

do shell script “shutdown -r now” user name cencoredusername password cencoredpw

But when I tried to compile it I got this message:

Systax Error Expected end of line, etc. but found identifier

What am I doing wrong?

And thanks for all your help! it is greatly appreciated

Thanks Alastor, I forgot about the Dictionary resource. (That’s how novice I am) I looked in there and I think I got the syntax corrected.

Thanks guys for all of your help!!

Don’t change the ‘do shell script’ line. Only change the string values to the right values. Then it should work just fine (i’ve tested it myself before posting).

Thanks for your help! I was missing the quotes around “username” and “passwd” the first time. And I did not understand why the “with administrator rights” was at the end. I learned why thanks to Alastor’s suggestion of looking in the Dictionary. It is working now. Thank you both!