Since OS X 10.9 mavericks, the behavior of the power button has been changed. When you press the power button for about 2 seconds, it will put macOS (OS X) in stand-by (sleep) mode.
With the following command you can use the power button function as in previous versions of OS X. By showing a dialog box for turning off the Mac and more.
Disable power button from putting your mac in Stand-by mode
Copy and paste the following command in OS X/macOS Terminal:
defaults write com.apple.loginwindow PowerButtonSleepsSystem -bool no
Hit the enter key and immediately the behavior of the power button will change. When you press the power button, the dialog box will appear with the potential to turn off your Mac and more.
Copy and paste the following command in OS X/macOS Terminal to revert to the original settings:
defaults write com.apple.loginwindow PowerButtonSleepsSystem -bool yes
All my Macs show the dialog and there is no preferences set. But anyway, thanks for the tip. I wanted the opposite behaviour. 😉
You can also just press control+ Power button (control+eject on older Macs or Apple Bluetooth keyboards) to get the same result 🙂