Hello again,
Me again with that securityspy app, this time I’m trying to get a script on a logged in user switch to that user from any other user when a script is run on said user.
To clarify
User A is logged in, so is user B.
Currenty user B is being used.
so when a script is run on the user A side the computer switched to user A from user B, or C, D, etc.
Is this possible?
This seems to be a big one so thank you in advance for even taking the time and interest solving this issue.
Pierre
property CGSession_path : "'/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession'"
-- compile a list of names for every user except the current user
set user_name_list to {}
set who_am_i to do shell script "whoami"
repeat with this_user in paragraphs 16 thru -1 of (do shell script "niutil -list . /users")
set this_user to word 2 of this_user
if this_user is not who_am_i then set end of user_name_list to do shell script "niutil -readprop . /users/" & this_user & " realname"
end repeat
-- sort the names into alphabetical order
set text item delimiters to ASCII character 10
set user_name_list to paragraphs of (do shell script "echo " & quoted form of (user_name_list as string) & " | sort -f")
set text item delimiters to ""
set the_user to choose from list user_name_list & "Login Window." with prompt "Fast User Switching"
if the_user is not false then
set the_user to beginning of the_user
if the_user is "Login Window." then
do shell script CGSession_path & " -suspend"
else
do shell script CGSession_path & " -switchToUserID " & (do shell script "id -u " & the_user)
end if
end if
Thanks, but how do I set it up, when I run the script it gives me a window to choose from the different users. Sorry I’m new to this scripting thing…
Pierre
Okay, try this then (stick the short user name into where it says):
property CGSession_path : "'/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession'"
property the_user : ".short user name." -- Insert short name here
do shell script CGSession_path & " -switchToUserID " & (do shell script "id -u " & the_user)
If you don’t know the short user name of a particular user, either look for it in the Accounts prefpane in System Preferences, or run this (inserting the ‘long’ or ‘full’ name of the user into where it says):
property the_user : ".user name." -- Insert full name here
do shell script "niutil -readprop . /users/" & the_user & " realname"
I did what you instructed but when I ran the script I get error: “niutil: can’t open directory /users/.user: No such directory”
Instructions on how to get your short name:
Open System Preferences. Go to ‘Accounts’. Go to the account to which you want to switch to. Read to where it says ‘Short Name:’, and remember it.
Now open the first script of my last reply. Go to the second line where it says:
and change the text between the quotes to your short name which you got out of System Preferences.
e.g.
Now your script should work.
just so we are on the same page:
property CGSession_path : “‘/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession’”
property the_user : “sjobs” – spy
do shell script CGSession_path & " -switchToUserID " & (do shell script "id -u " & the_user)
this time I get error: id: sjobs: no such user
thanks again for helping me with this
ok I tried this way:property CGSession_path : “‘/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession’”
property the_user : “spy” – spy
do shell script CGSession_path & " -switchToUserID " & (do shell script "id -u " & the_user)
and it works, I get spy’s login screen, but now I have to get it to type in my password and hit enter
pierre