lock screen after login mac script

Discussion in 'macOS' started by stuartrozier, Aug 3, 2017.

  1. stuartrozier macrumors regular

    Joined:
    Nov 12, 2011
    #1
    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
     
  2. Mr_Brightside_@ macrumors 68030

    Mr_Brightside_@

    Joined:
    Sep 23, 2005
    Location:
    Toronto
    #2
    May I ask why/what you're trying to accomplish?
     
  3. stuartrozier thread starter macrumors regular

    Joined:
    Nov 12, 2011
    #3
    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
     
  4. Tonsko macrumors 6502

    Tonsko

    Joined:
    Aug 19, 2010
    #4
    Get a script that you know is working, create a plist file for it and stick it launchdaemon with appropriate xml tags.
     
  5. stuartrozier thread starter macrumors regular

    Joined:
    Nov 12, 2011
    #5
    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,
     
  6. Mr_Brightside_@ macrumors 68030

    Mr_Brightside_@

    Joined:
    Sep 23, 2005
    Location:
    Toronto
  7. Crash0veride, Aug 3, 2017
    Last edited: Aug 3, 2017

    Crash0veride macrumors regular

    Crash0veride

    Joined:
    Oct 10, 2016
    Location:
    Cincinnati
    #7
    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.
     

    Attached Files:

  8. stuartrozier thread starter macrumors regular

    Joined:
    Nov 12, 2011
    #8
    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
     
  9. Crash0veride macrumors regular

    Crash0veride

    Joined:
    Oct 10, 2016
    Location:
    Cincinnati
    #9
    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.
     
  10. stuartrozier thread starter macrumors regular

    Joined:
    Nov 12, 2011
    #10
    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
     

Share This Page