Automatic login ...

I understand that the «.sh» suffixe is not required. Only the path format as to be consistent.

I also changed the file location and it is not working anymore. This is the new path: /Applications/Scripts/Shell\ scripts/SwitchToUser508.sh. Is there any problem to locate the file within the Applications folder ?

Is that the same file that wasn’t working before? The one created with Word? You can put it anywhere you like, but I believe the suffix is important.

I suggest you use this script to put it where you want:

set x to quoted form of "#!/bin/bash
idl=$\"`ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'`\"
echo $idl
idletime=\"100\"
if [ $idl -gt $idletime ]; then
/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID 410
/usr/bin/osascript <<EOT
delay 5
    set password_ to \"\"
tell application \"System Events\"
    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 tell
EOT
fi"
do shell script "echo " & x & " >  /Applications/Scripts/Shell\\ scripts/SwitchToUser508.sh"
do shell script "chmod +x  /Applications/Scripts/Shell\\ scripts/SwitchToUser508.sh"
do shell script "sleep 7; /Applications/Scripts/Shell\\ scripts/SwitchToUser508.sh"

No. It is the TextEdit (text format) file. The one that worked yesterday.

With the new file location (/Applications/Scripts/ShellScripts/SwitchToUser508.sh) and the fact that we created a UserAgent in Lingon explain why the script works from the ScriptEditor but not in Lingon ?

Yes. You’d have to change the location in Lingon too:

<?xml version="1.0" encoding="UTF-8"?> Label org.switch.onidle ProgramArguments [b]/Applications/Scripts/ShellScripts/SwitchToUser508.sh[/b] StartInterval 120

Be sure to use "\ " for any space in the path. I’m not sure what the path is now. Either:
/Applications/Scripts/ShellScripts/SwitchToUser508.sh
or
/Applications/Scripts/Shell\ Scripts/SwitchToUser508.sh

The script does not work with Lingon when nested inside the Applications folder. I tried it again from the first root level of my home folder and it works with Lingon.

Is it possible that because we have configured it as MyAgent that the file located at /Applications/Scripts/ShellScripts/SwitchToUser508.sh would not work ? With this file path, if I use your script with the ScriptEditor it works, but not with Lingon.

It’s possible. I’m not sure, but there might be something about it that requires write permissions in the folder, and if you’re not logged in as an administrator it might not work. I can’t try it until tonight, since I’m stuck on a PC. :mad:

Hi cwtnospam,

I am still having problems to automate the switching. It gets in conflict with the screen and energy saver. I am able to execute the script a first time (either in the Script Editor or with Lingon), but it is not repeating itself after the first execution.

I have set Lingon to execute the script every 60 seconds, expecting that when the idle time would be bigger than 900 seconds (15 minutes), it would switch to the 508 user. I am been playing around with your shell script to better understand it and have 2 questions for you:

  1. what does this statement exactly mean: do shell script “sleep 5; /Users/Nous/Permutation508.sh”

  2. since the shell script cannot input the username and password (as stated in one of your previous reply) why does it include 14 statements relating to the username and password ? I have converted these 14 lines in tonotes by putting «–» in front of the lines and the script executes anyway (see below)

Regards


Modified script …

#!/bin/bash
idl=$“ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'
echo $idl
idletime=“900”
if [ $idl -gt $idletime ]; then
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID 508
/usr/bin/osascript <<EOT
–delay 5
–set password_ to “()”
–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

  1. It means sleep the shell for 5 seconds, then run the shell script called Permutation508.sh that’s located in your home folder.

  2. It can use the user id and password, that’s why they’re in the script.

If Lingon calls the script once, it should call it again. Post what it says in the “Expert” tab.

If there’s a conflict with the screen saver or energy saver, set the script so that it will activate before they do. Then they can activate in the other account.

OK … The «On demand» checkbox was not selected. It seems to be OK now. I try out time settings with the energy and screen saver.

I have a "On idle» applescript routine that runs in the backgroud for another usage and I was able to add 2 statements to run the shell script (BTW I was also able to nest the script in the Applications folder, location that I was not able to use with Lingon). It seems also to be running OK. What is/are the advantages of Lingon over my “On idle” routine ?

For another purpose, what would be the shell script if I wanted to switch to the login window instead of switching user (without login out of the active user) ?

On idle needs to keep an applescript running. Since Launchd is always running, it only needs to call your shell script periodically.

This part:
#!/bin/bash
idl=$“ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'
idletime=“900”
if [ $idl -gt $idletime ]; then
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID 508
fi

does the login screen if the system has been idle for more than idletime seconds. The Applescript part (called by the shell script, it goes before the ‘fi’ in the script above) is what does the login:

/usr/bin/osascript <<EOT
delay 5
set password_ to “()”
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

By the way, is the password for your account: () ? Why do you put the parenthesis?

When the user as no password, the shell script switches to the user without showing the login window. I would like to show up the login window without switching to a specific user. How would you shell script that ?

In previous tests, «“”» would result in an error. StefanK suggested that we change that to «“()”». Since then, I did not have any error message. Maybe should I try it without «()» to be sure they were causing the error.

I don’t think you can, but it may be possible. The CGSession command isn’t very well documented.

I see where he suggested “¢¢¢¢” with the ¢ representing characters in the password, but not (). I think you’re losing a lot in the translation here. It would be a good idea to reread this entire thread to get a better understanding of what’s going on.

Hi,

Excuse the delay to give a reply, I was on vacation.

You were right, there was no “()”. So I must thank you very much for your help. I am now able to permutate to another user (giving that other user is not password protected) when my computer is idle for a certain amount of time.

I use a «On idle» routine that calls your shell script to execute when needed.

Thanks again alot.

If that works for you, then great! I think it might be more efficient to use launchd, but then again, maybe not.

Hi cwtnospam,

If I want a shell script that switches to another user (providing that that user has no password) without any other delay or condition, what would that script be ? Would it be:

… or is there more statements to include ?

Regards.

Robert

Try:

#!/bin/bash
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID 508

The osascript portion tells the shell to execute Applescript commands, and they’re not needed if there is no password.

Could these statements be included directly in an script with a «do shellscript» rather than by pointing to an external shellscript like we did ?

Regards.

Robert

Yes.

do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID 508"

The first '' tells Applescript to ignore the second '', which tells the shell script to ignore the space as a separator in the path.

How do you include a multiple statement shellscript in an AppleScript ? Like this one:

something like this


on idle
	set idleTime to (do shell script "ioreg -c IOHIDSystem | perl -ane 'if (/Idle/) {$idle=(pop @F)/1000000000; print $idle,\"\";last}'") as integer
	if idleTime > 900 then
		do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID 508"
	end if
	return 60
end idle