Skip to main content

Timeline for Lock Screen Command One-Liner

Current License: CC BY-SA 3.0

17 events
when toggle format what by license comment
Jan 5, 2019 at 10:59 comment added markhunte The Keychain menu item has now been removed by apple and a new Lock screen menu item in the Apple menu has been added. See update in my answer for detail.
Jun 30, 2017 at 9:07 comment added Lloeki This doesn't work aymore on 10.13 because the MenuExtra has been removed. This works instead: stackoverflow.com/a/26492632/368409
S Mar 1, 2017 at 20:35 history suggested Bruno Bronosky CC BY-SA 3.0
Based on the comments, the average Apple user needs a little more explanation on how to build this. I've made it totally copy-pasta.
Mar 1, 2017 at 20:12 review Suggested edits
S Mar 1, 2017 at 20:35
S Mar 2, 2015 at 19:22 history suggested mrb CC BY-SA 3.0
Change method call to avoid compile warning
Mar 2, 2015 at 19:08 review Suggested edits
S Mar 2, 2015 at 19:22
Jan 31, 2015 at 21:46 comment added jbrock Thank you so much for posting the code above! I work in a computer lab and lock the screen every time I step away from my computer. I created the above script. Then I used appify to turn it into an OS X app, mathiasbynens.be/notes/shell-script-mac-apps. Then I used Quicksilver to assign my own keyboard shortcut (cmd+L). Now I just use that instead of having to lock the screen by using the mouse to click on the keychain icon in the top bar. Once again, I really appreciate this. Terminal is not opening/staying open with how I have it set up because I am launching an OS X app instead.
Dec 7, 2014 at 17:21 comment added Mengdi Gao I collected an OS X App: Lock Screen.app based on this answer and somebody's work as detailed in the link, it simply wraps this code and add an beautiful icon, so we can run it directly, thank you.
S Mar 10, 2014 at 11:36 history suggested Saaru Lindestøkke CC BY-SA 3.0
made answer more complete with a comment of OP
Mar 10, 2014 at 11:01 review Suggested edits
S Mar 10, 2014 at 11:36
Mar 10, 2014 at 10:44 comment added bit_drifter I'm aware of the warning. The program is more like a proof of concept than a well-thought-out program. it would be possible to make a full mac os application from this executable, that would prevent the terminal being opened. but on the other hand if you wanted to click on something to lock the screen, why not use the keychain menu plugin itself? i intended this program to be called by some other process (e.g. launchbar). that way no terminal is spawned.
Mar 10, 2014 at 10:11 comment added Saaru Lindestøkke Tried it, works as described. The compilation generates one warning instance method '-_lockScreenMenuHit:' not found, but the lockscreen application works nonetheless. However, when doubleclicked it opens a Terminal window before it locks the screen. After unlocking you have to close the window manually. Is there a way to close that window automatically?
Mar 10, 2014 at 1:19 comment added bit_drifter This is a simple Objective-C Program. Copy it into a file called main.m. Then run 'clang -framework Foundation main.m -o lockscreen' to compile the program. './lockscreen' runs the program and locks your screen.
Mar 10, 2014 at 1:09 comment added Saaru Lindestøkke Could you elaborate on how to use this? Do I copy-paste this into an Automator workflow? Or make an Applescript out of it? As it stands now it's hard to do something with your answer.
S Mar 9, 2014 at 22:29 review Late answers
Mar 10, 2014 at 0:58
S Mar 9, 2014 at 22:29 review First posts
Mar 10, 2014 at 1:53
Mar 9, 2014 at 22:11 history answered bit_drifter CC BY-SA 3.0