Automatic login ...

I am not sure if your script applies. I want, when inactive for a specified amount of time, to log out of any user and to log in a specific non-passworded user automatically …

It was just an example. See my altered script above.

no escaped quotes in this line?

To cwtnospam: My reply was to StefanK … But I tried your new script (after having modified “SecurityAgent” to "System Events") and it didn’t work. The script hangs and there is no switch.

Hmmm, let’s try it this way then:

set x to quoted form of "#!/bin/bash
idl=$\"`ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'`\"
echo $idl
idletime=\"5\"
if [ $idl -gt $idletime ]; then
/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID OTHERUSERID
/usr/bin/osascript <<EOT
delay 5
set password_ to \"OTHERUSERPASSWORD\"
tell application \"System Events\"
try
tell process \"SecurityAgent\" to set value of text field 1 of group 1 of window 1 to password_
click button \"Log In\" of window 1 of application process \"SecurityAgent\"
on error
delay 1
tell process \"SecurityAgent\" to set value of text field 1 of group 1 of window 1 to password_
click button \"Log In\" of window 1 of application process \"SecurityAgent\"
end try
end tell
EOT
fi"
do shell script "echo " & x & " > ~/SwitchToUser.sh"
do shell script "chmod +x ~/SwitchToUser.sh"
do shell script "sleep 7; ~/SwitchToUser.sh"

Do I have to change something in the script ? I run it as sent, like your asked. When I run it, it does not hang, but it is long to resolve and it gives me this error message:

298:359: execution error: System Events got an error: NSReceiverEvaluationScriptError: 4 (1)

What Mac do you have and how much RAM does it have? It seems like the system isn’t responding fast enough. Try to keep as few applications open as possible.

Also, you do have Fast User Switching enabled, right?

I have an iMac G5 1.6 mgz with 2 GB of RAM running OS 10.4.11. Fast user switching is also enabled …

Does the script bring up the login screen?

The only thing I get is an error message in the Script editor. No login screen !

What does OTHERUSERID and OTHERUSERPASSWORD refer to ? I did not change anything in your script as you requested …

Replace OTHERUSERID with the user id: 508

Replace OTHERUSERPASSWORD with that user’s password. If there is none, delete OTHERUSERPASSWORD, leaving just ""

OK corrections done. Automatic switching to 508 worked, but the Script editor still gave this message error:

281:342: execution error: System Events got an error: NSReceiverEvaluationScriptError: 4 (1)

Does that mean that the login screen appeared and then you got the error?

That user does not have a password, so OS X switched to 508 without the login screen. I tried one with a password and the login screen was displayed. The error message also:

289:350: execution error: System Events got an error: NSReceiverEvaluationScriptError: 4 (1)

It is not my objective to switch to a passworded user, but I just want to know … What is the point to configure a script with a user # and password if it is not to automatically trigger the switching ?

I don’t know what’s going on there, but if it’s working for user 508, then all you need to do is adjust idletime to an appropriate number of seconds for your needs and use Lingon to periodically call the script. If you call the script every 120 seconds and idletime is set to 100 seconds, then it could be anywhere from 100 seconds to 220 seconds after you stop using the computer before the switch occurs.

Right now idletime is set to 5 seconds, which means that every time the script is run, if the system has been idle for more than 5 seconds, it will switch. So if you set Lingon to call it every 2 minutes (120 seconds) there’s a good chance it would switch any time it got called.

I will try the shell script with Lingon and see if the error message have any impact. I don’t know that utility at all … It seems to have many options and possible configurations :/:/:confused:

Do I have to create a «User Agent» or a «User Daemon» ?
What are the different «ProgramArguments» that I need to enter in the first page ?
Is there any other configuration that I should know of other that the «StartInterval» ?

Thanks again …

You want to create a new agent under “My agents” and then copy/paste the xml below into (and in place of everything in) the box in the “expert” tab. You will see that all of the appropriate fields in the other tabs will fill in. You may want to change the StartInterval to something other than 120 seconds, and you’ll definitely want to change the idletime in the actual script to be longer than 5 seconds! I’m thinking 100 might be good.

By the way, I’ve run the script on my machine several more times and the only way I can get it to error is with a nonexistent user id or with “Enable access for assistive devices” unchecked in the Universal Access System Preferences pane.

<?xml version="1.0" encoding="UTF-8"?> Label org.switch.onidle ProgramArguments /users/Nous/SwitchToUser.sh StartInterval 120

I will try it and give you feedback later … Thank you for your great patience. The world is a better place with helpful people like you :):):slight_smile:

Everything seems to be OK.

I would like to rename the file. Can Lingon target any file as long it’s the content is a shell script in text only format or has it to be renamed with the «.sh» suffixe ?

Yes, as long as it’s a valid POSIX path. While “/users/Nous/SwitchToUser.sh” is valid, “/users/Nous/Switch To User.sh” is not because of the spaces. You would need to ‘escape’ the spaces with a backslash: “/users/Nous/Switch\ To\ User.sh”