lock screen after login mac script

stuartrozier

macrumors 6502
Original poster
Nov 12, 2011
252
6
Hello,

I'm after creating an applescript or workflow, so that the computer will lock the screen straight after login,

so im disabling the password log-in screen, and going to use auto login,

but then i need the computer to lock straight after,

is this possible ?

i read of a script somewhere, tested it, but it wasn't working,

this is what i found on searching the web,

/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend

many thanks in advance,

stuart
 

stuartrozier

macrumors 6502
Original poster
Nov 12, 2011
252
6
May I ask why/what you're trying to accomplish?
So,

I'm after the auto log in feature, so the mac will load to desktop instantly bypassing the login screen, which i can accomplish already using the log in options,
but..
I'm then after a service/workflow, that'll instantly lock or sleep the screen after about 5-10 seconds after the desktop has loaded,

I'm using dssw power manager to wake mac at a certain time, which is successful,

but then after its booted up, logged in automatically, i need it to almost instantly lock screen or sleep after a few seconds,

i have a my mac on 24/7, an I'm wanting to give it a rest at night when i sleep,

but after auto login, i just need the screen to switch the screensaver on after about 5-10 seconds allowing applications to load up, and then sleep to the login screen,

stuart
 

Tonsko

macrumors 6502
Aug 19, 2010
293
1
Get a script that you know is working, create a plist file for it and stick it launchdaemon with appropriate xml tags.
 

stuartrozier

macrumors 6502
Original poster
Nov 12, 2011
252
6
Get a script that you know is working, create a plist file for it and stick it launchdaemon with appropriate xml tags.
well i haven't found any that work, but i was wondering if anybody knows of any apps or scripts that might be able to accomplish this,
 

Crash0veride

macrumors regular
Oct 10, 2016
179
89
Cincinnati
That terminal line can be used with automator to make an app. Just drag it into the login items in the account section after you save the app to your applications. I made this one in automator in 2 seconds, but I put a 1 minute delay in so that there would be less complications from immediately launching it after login. You can open the app with automator and edit or delete the delay.

Also

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

is an applescript that would do the same thing (execute terminal command), if you absolutely need it as a script.
 

Attachments

Last edited:
  • Like
Reactions: stuartrozier

stuartrozier

macrumors 6502
Original poster
Nov 12, 2011
252
6
Would energy saver prefs (1 minute) do this?
it would yes, but i just need it to be a bit more rapid/quick after login than that,
That terminal line can be used with automator to make an app. Just drag it into the login items in the account section after you save the app to your applications. I made this one in automator in 2 seconds, but I put a 1 minute delay in so that there would be less complications from immediately launching it after login. You can open the app with automator and edit or delete the delay.

Also

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

is an applescript that would do the same thing (execute terminal command), if you absolutely need it as a script.

brilliant, i also found one in the last 15mins of searching, created in automator - saved it as an app, and added it to the login items screen,
but yeah your right - it is instant - it may be too instant haha, do applications still load in the background even when slept ?

if not, where or how would i add the delay ?

thank you
 

Crash0veride

macrumors regular
Oct 10, 2016
179
89
Cincinnati
it would yes, but i just need it to be a bit more rapid/quick after login than that,



brilliant, i also found one in the last 15mins of searching, created in automator - saved it as an app, and added it to the login items screen,
but yeah your right - it is instant - it may be too instant haha, do applications still load in the background even when slept ?

if not, where or how would i add the delay ?

thank you
They should load in the background, but I've had issues running scripts immediately after login (script doesn't finish). In automator you just add a "pause" action before the shell or script command.
 
  • Like
Reactions: stuartrozier

stuartrozier

macrumors 6502
Original poster
Nov 12, 2011
252
6
They should load in the background, but I've had issues running scripts immediately after login (script doesn't finish). In automator you just add a "pause" action before the shell or script command.
perfect - done it- tested it - works smoothly with a delay too - been able to add a few more things too like mounting network drives .. star - thank you, appreciate that
 
  • Like
Reactions: Crash0veride
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.