Skip to main content

Execute a script when the app is terminated

When the end-user exits the application with the Quit button or with the quit shortcut (either ⌘Q or ⌃⌥⌘Q depending on AppTerminationQuitSohrtcutIsEnabled), you can ask Octory to execute a script at a given path.

Something useful to be aware of is that you can specify a different script to be executed depending on the overall installation state of the monitors. To do so, the keys IncompleteInstallationScriptPath and CompleteInstallationScriptPath have to be specified in AppTermination.

It is worth to know that starting from macOS 10.15, Octory will not always have the correct rights to execute scripts in /Library/Application Support/ Octory. For example, if a script tries to write in a file at /Library/Application Support/ Octory or in the user home folder, it will not work.

With Octory 2.0.3 and higher, you can read the logs in /tmp to know whether the script execution was successful or not. For example, you might read that the script has some instructions which require the root privileges to be executed.


Choose another folder

When writing in a file which requires root privileges to be written, you can move this file to another folder for which Octory will have the rights to write in, like the /Users/Shared folder.

Change the script

Sometimes, if a command requires root privileges to be executed, another one exists with a similar feature, but which requires less rights to be executed. For example, to restart or shutdown the Mac, the command reboot requires root privileges, but you can use the osascript one:

osascript -e 'tell app "System Events" to restart'

The same goes to shutdown the machine:

osascript -e 'tell application "Finder" to shut down'

Execute the script with the Helper

If you do need the root privileges to execute a script, you can ask Octory to use the Helper to execute the script. To do so, simply set the key ExecuteAsRoot to True in AppTermination. You can read this tip to learn how to install the privileged Helper.

Discover more