• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: switching user using apple script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: switching user using apple script


  • Subject: Re: switching user using apple script
  • From: "J. Stewart" <email@hidden>
  • Date: Mon, 26 Nov 2007 09:44:37 -0500

On 11/25/07 at 11:17 PM, chinni <email@hidden> spake thusly:

Any one help me from this...waiting for u r replies...

On Nov 22, 2007 12:33 AM, chinni <email@hidden> wrote:

Hi ,
I am new apple script.I would like to run apple script for fast user
switch to another user and wait for 15min and again login back to current
user.
The below is the script but how can i pass the other user name and passwd
in the script to login and wait for 15min of time and again login back to
current user.can any one help me from this

Leaving the second account logged in?



try
    try
        set the_path to (((path to library folder from system domain) as
Unicode text) & "CoreServices:Menu Extras:
User.menu:Contents:Resources:CGSession ")
        set the_path to quoted form of POSIX path of the_path
        set the_arguments to " -suspend"
        do shell script the_path & the_arguments
    end try
    delay 2
    try
        do shell script "pmset force -a hibernatemode 1"
        ignoring application responses
            --tell application "System Events" to sleep
        end ignoring
    end try
end try



Thanx in advance

Generally when you don't get a response it's because no one knows an answer or there is no answer.


In this case (I haven't tried it), I suspect what you are attempting isn't possible given the security aspects of OS X. An Applescript running in user account 1 shouldn't be able to do what you are trying to do in user account 2.

Inclusion of passwords in scripts isn't a very good idea either as they are easily extractable by anyone who knows anything about computers. All you need do is open the file with the proper kind of editor or run the unix "strings" command on the script file. Storing the passwords in an encrypted file accessible to both scripts would be one possible option.

Given the above here's what I'd suggest -

This script switches to a specified user account. You will need to enter that user account's password when it's run as there are no provisions in it for storing a password. Use it in the first user account to switch to the second one.

--> Cut <-- script 1
set un to "shortnameofusergoeshere"
set uid to text 5 thru 7 of (do shell script "id " & un)
set scpt to "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID " & uid
do shell script (scpt)
--> Cut <--


This script logs out an account after 15 minutes. It should be saved as a stay open script and run from either the user's login items or launchd. As written it will ALWAYS try to log out the account so you would need to add a toggle to the script so it will quit if the login isn't initiated by script 1. For instance, have script 1 make an empty text file in the shared folder and script 2 check for it's existence. Script 2 should quit immediately if the file doesn't exist and should also provide for removal of the file if it does exist.

--> Cut <-- script 2
property firstRun : true
on idle
	if firstRun then
		set firstRun to false
		return (15 * minutes)
	else
		set firstRun to true
		ignoring application responses
			tell application "loginwindow" to «event aevtrlgo»
			-- use the shell script from script 1 to switch instead of logout
		end ignoring
	end if
end idle
--> Cut <--

This can create a toggle file as mentioned above -

--> Cut <--
do shell script "touch /Users/Shared/SwTest.txt"
--> Cut <--

and this will test for and remove that file -

--> Cut <--
tell application "Finder" to set tst to exists POSIX file "/Users/Shared/SwTest.txt"
if tst then do shell script "rm /Users/Shared/SwTest.txt"
--> Cut <--

This doesn't really accomplish your stated intent but it's the best I could come up with on short notice.

JBS
--
Any sufficiently advanced technology is indistinguishable from magic.  -Arthur C. Clarke
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users


This email sent to email@hidden
References: 
 >Re: switching user using apple script (From: chinni <email@hidden>)

  • Prev by Date: Determining
  • Next by Date: Re: Eject in Leopard - some clues
  • Previous by thread: Re: switching user using apple script
  • Next by thread: Re: switching user using apple script
  • Index(es):
    • Date
    • Thread