So is there a reliable way to change the value of a variable on shutdown.
Open Terminal.app, input:
man shutdown
Enter,then you get:
SHUTDOWN(8) BSD System Manager's Manual SHUTDOWN(8)
NAME
shutdown -- close down the system at a given time
SYNOPSIS
shutdown [-] [-h [-u] | -r | -s | -k] [-o [-n]] time [warning-message ...]
DESCRIPTION
The shutdown utility provides an automated shutdown procedure for super-users to nicely notify users when the system is shutting down, saving them from system
administrators, hackers, and gurus, who would otherwise not bother with such niceties.
The following options are available:
-h The system is halted at the specified time.
-k Kick everybody off. The -k option does not actually halt the system, but leaves the system multi-user with logins disabled (for all but super-user).
-n If the -o is specified, prevent the file system cache from being flushed by passing -n option to halt(8) or reboot(8). This option should probably not be
used.
-o If -h or -r is specified, shutdown will execute halt(8) or reboot(8) instead of sending a signal to launchd(8).
-r The system is rebooted at the specified time.
-s The system is put to sleep at the specified time.
-u The system is halted up until the point of removing system power, but waits before removing power for 5 minutes so that an external UPS (uninterruptible
power supply) can forcibly remove power. This simulates a dirty shutdown to permit a later automatic power on. OS X uses this mode automatically with sup-
ported UPSs in emergency shutdowns.
time Time is the time at which shutdown will bring the system down and may be the word now (indicating an immediate shutdown) or specify a future time in one of
two formats: +number, or yymmddhhmm, where the year, month, and day may be defaulted to the current system values. The first form brings the system down in
number minutes and the second at the absolute time specified.
warning-message
Any other arguments comprise the warning message that is broadcast to users currently logged into the system.
- If `-' is supplied as an option, the warning message is read from the standard input.
At intervals, becoming more frequent as apocalypse approaches and starting at ten hours before shutdown, warning messages are displayed on the terminals of all
users logged in.
At shutdown time a message is written to the system log, containing the time of shutdown, the person who initiated the shutdown and the reason. Corresponding sig-
nal is then sent to launchd(8) to respectively halt, reboot or bring the system down to single-user state (depending on the above options).
A scheduled shutdown can be canceled by killing the shutdown process (a SIGTERM should suffice).
SIGTERM TO SIGKILL INTERVAL
Upon shutdown, all running processes are sent a SIGTERM followed by a SIGKILL. The SIGKILL will follow the SIGTERM by an intentionally indeterminate period of
time. Programs are expected to take only enough time to flush all dirty data and exit. Developers are encouraged to file a bug with the OS vendor, should they
encounter an issue with this functionality.
SEE ALSO
kill(1), login(1), wall(1), halt(8), launchd(8), reboot(8)
BACKWARD COMPATIBILITY
The hours and minutes in the second time format may be separated by a colon (``:'') for backward compatibility.
HISTORY
The shutdown utility appeared in 4.0BSD.
BSD December 11, 1998 BSD
Thanks, but I'm not getting where this gives me any kind of trigger on shutdown.
Keyboard Maestro does not have a trigger for Shut Down
. You could possible trigger it some other way (eg using Control Plane maybe), but then Keyboard Maestro might already be terminated.
What are you trying to do?
While there is not a "Shutdown" trigger, you can write a Macro to perform whatever actions you want, then shutdown your Mac.
I have such a Macro I use daily when I'm ready to shutdown. I trigger it by name just by typing "shut".
Here's my shutdown macro. Adjust to suit your needs/preferences:
MACRO: [SHUT DOWN] Close Apps, Unmount Drives, & Shut Down
#### DOWNLOAD:
<a class="attachment" href="/uploads/default/original/3X/f/f/ffd0be71597acb77f0ae52425c67db87fef1a886.kmmacros">[SHUT DOWN] Close Apps- Unmount Drives- & Shut Down.kmmacros</a> (30 KB)
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**
---
### ReleaseNotes
Author.@JMichaelTX
PURPOSE:
* **Prepare it, and then actually shutdown MY Mac**
* This is _highly_ customized for my Mac, my needs
* _YMMV_
* Quit ALL Apps
* Special Handling for Some Apps
* Check for Unsaved Files
* Unmount All External Drives
* Finally, confirm and shutdown my Mac
**MACRO SETUP**
* Trigger: Assign as needed/preferred
* I use Trigger by Name ("shut")
TAGS: @Shutdown @Unmount @Quit @JMichaelTX
USER SETTINGS:
• Any Action in magenta color is designed to be changed by end-user
• This macro uses Google Search and Google Chrome, but can be easily changed
ACTION COLOR CODES
• To facilitate the reading, customizing, and maintenance of this macro,
key Actions are colored as follows:
• GREEN -- Key Comments designed to highlight main sections of macro
• MAGENTA -- Actions designed to be customized by user
• YELLOW -- Primary Actions (usually the main purpose of the macro)
• ORANGE -- Actions that permanently destroy Varibles or Clipboards
REQUIRES:
(1) Keyboard Maestro Ver 7.2.1+
(2) Yosemite (10.10.5)+
---
![image|690x1246](upload://oKvykE0jugBUjiK3LYb5CV2Ymt2.png)
Thanks.
I had a sneakin' suspicion that was on your mind. That may be what I have to do, but if someone should forget to use the new method and shutdown the machine from the Apple menu, the consequences could be rather severe.
As usual, making this way more complicated than it needs to be. I think I've got it sorted out (simplified).
(c;
Hey Scott,
Run a script only at shutdown (not log off or restart) on Mac OS X
It appears that EventScripts has a ShutDown event.
No guarantee that Keyboard Maestro will still be running when either of these methods take effect, but you can always write a variable to disk and read it back when Keyboard Maestro starts up.
-Chris
Thanks Chris... good to know.
I took another look at this thing from the ground up and no longer need a shutdown trigger... just assume it's off unless we get a login or wake event.
That will greatly simplify things.