Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

applescript to login user after scheduled startup

Hi,


I am trying to get the MACs in the office to:


at a set time - do a TM backup.


after backing up shutdown the MAC


Next morning startup, login the/a user loading any apps that were in use before the previous shutdown and sleep (which the MAC will do anyway after a period of inactivity anyway)


Thus the backup, shutdown and restart are effectively invisible to the user -unless they have left blocking apps open.


I have pretty much got it sorted. But I can't find a way to login the user after a scheduled startup using apple script.


Currently a crontab runs this applescript:-



(* next wake time - set for just before DoBackup is scheduled *)

do shell script "pmset repeat wakeorpoweron MTWRF 18:55:00" password "LoginPassword" with administrator privileges


(* login *)

tell application "System Events"

tell application process "loginwindow"

keystroke "LoginName"


keystrokereturn

delay 3.0

keystroke "LoginPassword"

delay 3.0


keystroketab


keystrokereturn

end tell

end tell



Am I trying to do something that I just can't achieve?


Is there a simple way of achieving this?


Andy C


Posted on Sep 20, 2013 7:18 AM

Reply
Question marked as Best reply

Posted on Sep 20, 2013 12:09 PM

AFAIK you can't do this - you can't run a user-side script to effect a login like this.


However, it makes me wonder what it is you're trying to achieve here. What are you hoping to gain from the shutdown/startup sequence? Why not just let the machine sleep overnight?

11 replies

Sep 20, 2013 1:05 PM in response to dinmakers

Isn;t having the machines boot and automatically login the same as having no login on the machine?


The machine is just going to be sitting there logged in with no user on it, seems like either a bit of a security breech or else telling you there is no need for the user to login.


Just have the system automatically login to the user you were going to login in the script. Set Automatic login that user in Users & Groups. Accomplishes the same thing.

Sep 20, 2013 1:08 PM in response to Camelot

There is a lot of discussion about this online.


The upshot seems to be that, depending on your model, sleep mode draws a trivial amount of power - so little that many consumer power meters can't even gauge how much, which means less than 1W. Conversely, the overhead of shutting down and powering back up actually uses more power than leaving the machine to sleep overnight.


So a noble thought, but one that doesn't seem to have much benefit.

Sep 20, 2013 1:20 PM in response to Frank Caggiano

I did think about that. But as the machines have been configured to force a login I didn't to change that. I suspect that option is still available to me, but as Camelot has pointed out there is more power consumed shutting down and booting up than would be consumed overnight in sleep mode. The MACs in question are only 18 months or so old so should fall into Camelot's category.


Thanks.

Sep 20, 2013 1:56 PM in response to Frank Caggiano

If idle is sleep then that contradicts Camelot. I'm just gonna have to dig the documentation out.


Further to why keep the machines with a forced login:


They are set to require a password to wake. So if I power up and login with a script I can then tell them to sleep immediately (not yet in the script) and access is then restricted.


If set to automatically login a casual user could simply power up and gain access.

Sep 20, 2013 2:13 PM in response to dinmakers

idle is not sleep.


Idle means the machine is powered up, ready to do something, but no one is actively using the system - it's not downloading anything, rending anything, playing any video, reading/writing data to disk, etc. Most people's systems spend a significant amount of time in this state, but it's still running numerous background processes even if there's no user at the helm.


A number of system components can reduce their power consumption when 'idle', ready to spring back to action at a millisecond's notice. Indeed, the CPU can draw a significant difference in power depending on how much work it's being asked to do.


So idle is not the same as sleep. Sleep preserves only the system RAM, minimal components to detect wake events (e.g. keyboard presses, possibly network), and not much more.

Nov 22, 2013 12:37 PM in response to dinmakers

I might be missing something here, but a Lion (10.7) or later Mac can shut down, start up, log in and resume apps entirely with existing bits of the GUI with no scripting.


Unless you have multiple users and want the last user to be the login. That would need some custom stuff.


That said, it is possible to script the login process, because it is often used by folks with ARD to get a machine to log in (and looking for that code is what brought me here). You may have to run the AppleScript as root to be allowed to do system events in the login window.

applescript to login user after scheduled startup

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.