Skip to content

Stop-Computer, Restart-Computer on macOS: support graceful shutdown by default, implement -Force support #19791

@mklement0

Description

@mklement0

Summary of the new feature / enhancement

Note:


A fix for #19738 is being worked on in #19780, and it will delegate to /sbin/shutdown -h now (shutdown) and /sbin/shutdown -r now (reboot) on macOS.

However, these commands amount to a forced shutdown: they do not afford GUI applications enough time to shut down gracefully, such as browsers and VM software, inducing potential data loss.

Therefore, I propose the following:

Proposed technical implementation details (optional)

By default, use the following commands on macOS - they do shut down gracefully, but - as on Windows - do not guarantee a shutdown, if an app refuses to quit:

  • Shutdown:
    • osascript -e 'tell application "System Events" to shut down'
  • Reboot:
    • osascript -e 'tell application "System Events" to restart'

Use /sbin/shutdown ONLY if -Force is specified.

  • Shutdown:
    • /sbin/shutdown -h now
  • Reboot:
    • /sbin/shutdown -r now

Note that the "graceful" commands do not require sudo, i.e. administrative privileges, whereas /sbin/shutdown always does.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugKeepOpenThe bot will ignore these and not auto-closeUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdlets-Managementcmdlets in the Microsoft.PowerShell.Management moduleWG-ReviewedA Working Group has reviewed this and made a recommendation

    Type

    No type

    Projects

    Status

    Reviewed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions