Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Rok73

macrumors 65816
Original poster
Apr 21, 2015
1,160
516
Planet Earth
Title nearly says it all. I want some kind of (two?) shortcut(s) to switch between different times until the Lock Screen is activated. What's the easiest way to do this? Are there probably different ones? I am on macOS Ventura 13.2.1.

On a side note: I hate the way the settings are organized on Ventura. Terrible, ugly. Things are hard to find. I am on board since Snow Leopard, I think.
 

bogdanw

macrumors 601
Mar 10, 2009
4,862
2,259
From Terminal:
for immediately
Code:
sudo sysadminctl -screenLock immediate -password AdminPassword
for 5 minutes
Code:
sudo sysadminctl -screenLock 300 -password AdminPassword
Time is expressed in seconds.
 
  • Like
Reactions: Rok73

Rok73

macrumors 65816
Original poster
Apr 21, 2015
1,160
516
Planet Earth
From Terminal:
for immediately
Code:
sudo sysadminctl -screenLock immediate -password AdminPassword
for 5 minutes
Code:
sudo sysadminctl -screenLock 300 -password AdminPassword
Time is expressed in seconds.
Thanks for that. Any way to make some kind of quick access out of that?
 

bogdanw

macrumors 601
Mar 10, 2009
4,862
2,259
Thanks for that. Any way to make some kind of quick access out of that?
I’ve tried to make it into a simple app with AppleScript, but for an unknown reason it doesn’t work.
Here is the code, example for an admin user named “Admin” with the password “1234”:

Code:
set ScreenLockStatus to do shell script "sysadminctl -screenLock status"
set question to display dialog "The screen lock is set to: " & ScreenLockStatus & return & "Would you like to:" buttons {"Set to immediate", "Set to 5 minutes", "Cancel"} default button 1
set answer to button returned of question
if answer is equal to "Set to immediate" then
    do shell script "sudo sysadminctl -screenLock immediate -password 1234" user name "Admin" password "1234" with administrator privileges
end if
if answer is equal to "Set to 5 minutes" then
    do shell script "sudo sysadminctl -screenLock 300 -password 1234" user name "Admin" password "1234" with administrator privileges
end if
if answer is equal to "Cancel" then
    return
end if
 
  • Like
Reactions: Rok73

Rok73

macrumors 65816
Original poster
Apr 21, 2015
1,160
516
Planet Earth
I find Ventura settings much easier to use. Just use the View menu pulldown where all of the settings are listed alphabetically.
I’ll give that a try, thanks.
I’ve tried to make it into a simple app with AppleScript, but for an unknown reason it doesn’t work.
Here is the code, example for an admin user named “Admin” with the password “1234”:

Code:
set ScreenLockStatus to do shell script "sysadminctl -screenLock status"
set question to display dialog "The screen lock is set to: " & ScreenLockStatus & return & "Would you like to:" buttons {"Set to immediate", "Set to 5 minutes", "Cancel"} default button 1
set answer to button returned of question
if answer is equal to "Set to immediate" then
    do shell script "sudo sysadminctl -screenLock immediate -password 1234" user name "Admin" password "1234" with administrator privileges
end if
if answer is equal to "Set to 5 minutes" then
    do shell script "sudo sysadminctl -screenLock 300 -password 1234" user name "Admin" password "1234" with administrator privileges
end if
if answer is equal to "Cancel" then
    return
end if
Hm, thanks, I guess. 😁

Is there a way to execute the sudo thingy when I start a specific app e.g.? And quit it?
 

bogdanw

macrumors 601
Mar 10, 2009
4,862
2,259
You can put the same command in a .command file, but that means your password is stored in a plain text file.
Example of a command file, created with TextEdit – plain text, that sets lock screen to 5 minutes and then opens Calculator:
Code:
#!/bin/zsh
sudo sysadminctl -screenLock 300 -password 1234
open -a /System/Applications/Calculator.app
 

bogdanw

macrumors 601
Mar 10, 2009
4,862
2,259
@Rok73 Thanks to some outside help :) the script is fixed and can be saved as as app.
I’ll explain step by step
- Open Script Editor (/Applications/Utilities/Script Editor.app )
- Copy-paste the code below, with your password instead of 1234
Code:
set ScreenLockStatus to do shell script "sysadminctl -screenLock status 2>&1 | awk -F'] ' '{print $2}'"
set question to display dialog "The screen lock is set to: " & ScreenLockStatus & return & "Would you like to:" buttons {"Set to immediate", "Set to 5 minutes", "Cancel"} default button 1
set answer to button returned of question
if answer is equal to "Set to immediate" then
    do shell script "/usr/sbin/sysadminctl -screenLock immediate -password 1234"
end if
if answer is equal to "Set to 5 minutes" then
    do shell script "/usr/sbin/sysadminctl -screenLock 300 -password 1234"
end if
if answer is equal to "Cancel" then
    return
end if

- from Script Editor - File - Export – choose a name and the location where to save the app, File Format – Application, Run-only, Don’t sign code.
Now you can run the app and you will see these options.
screenLock.jpg
The script can be modified with different values for seconds or off instead of immediate, if you want to turn it off.

Apple Save a script as an app in Script Editor on Mac https://support.apple.com/guide/script-editor/save-a-script-as-an-app-scpedt1072/mac
 
  • Like
Reactions: ignatius345

bogdanw

macrumors 601
Mar 10, 2009
4,862
2,259
A version with multiple choices:
Code:
set ScreenLockStatus to do shell script "sysadminctl -screenLock status 2>&1 | awk -F'] ' '{print $2}'"
set theLockChoices to {"Immediate", "1 minute", "5 minutes", "Off"}
set theLock to choose from list theLockChoices with prompt ScreenLockStatus & return & "Set to:" default items {"1 minute"}
if theLock = {"Immediate"} then
    do shell script "/usr/sbin/sysadminctl -screenLock immediate -password 1234"
end if
if theLock = {"1 minute"} then
    do shell script "/usr/sbin/sysadminctl -screenLock 60 -password 1234"
end if

if theLock = {"5 minutes"} then
    do shell script "/usr/sbin/sysadminctl -screenLock 300 -password 1234"
end if
if theLock = {"Off"} then
    do shell script "/usr/sbin/sysadminctl -screenLock off -password 1234"
end if

ScreenLockStatus.png
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.