Create PKG / Script to send Lock Computer Command

Ricardo_Mouta
New Contributor

Hi Nation,

My goal is to create a pkg or a script that will run if Ethernet Cable is removed from an iMac and it will lock that machine.
But I am "stucked" on Lock Computer Command.
My question is: Is it possible to run the command using Terminal application?

Many thanks in advance.

5 REPLIES 5

cddwyer
Contributor

You could just send the command "/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession -suspend"

Hope that helps.

Ricardo_Mouta
New Contributor

Hello @cddwyer many thanks for your reply.

Really appreciated your quick feedback but is not exactly what I am searching for.
My goal is to block the Machine with a Pin Code.

Many thanks in advance

mm2270
Legendary Contributor III

The only possible way right now to do this is by using the Jamf API, which would trigger an APNs command against that device, which in turn would need an internet connection.
You said you wanted to run this when an Ethernet cable is disconnected, which is a bit odd. What exactly is the issue you're looking to solve? Will the Mac have a Wi-Fi connection when Ethernet is unplugged? Because if not, there's no way the Mac will receive the APNs command to lock it. It's not possible to do that kind of pin lock with a local shell command.

cddwyer
Contributor

If you can figure out how to trigger it locally, put in a script with a check for ethernet connection at the beginning, then into a policy and make it available offline and set the trigger to 'at network state change'.

Hope that helps.

Nix4Life
Valued Contributor

you should be able to modify one of those scripts that check if there is an Ethernet connection, then disable wifi. It could be a launch daemon on the client.

L