0

I'm making a little software to shutdown my computer after some time (with a countdown)

But I can't find how to send a "shutdown" command with my programm.

In my idea when the countdown is over the Mac simply shutdown.

Thanks you for any reply :)

Pablo Clsn
  • 13
  • 1
  • 6

1 Answers1

0

You can do something like that via AppleScript and Cocoa:

import Cocoa
let source = "tell application \"Finder\"\nshut down\nend tell"
let script = NSAppleScript(source: source)
script?.executeAndReturnError(nil)

You can also find a solution by using NSTask and a shell script.

These two solutions are only working if the sandbox is disabled.

Jeremy Vizzini
  • 261
  • 1
  • 9