2 summary:: register objects to be cleared when Cmd-. is pressed
3 related:: Classes/ShutDown, Classes/ServerQuit
8 CmdPeriod allows you to register objects to perform an action when the user presses Cmd-. These objects must implement a method called strong::-cmdPeriod:: which performs the necessary tasks. (You can add such a method in your custom classes.) Note that since link::Classes/Function:: implements strong::-cmdPeriod:: as a synonym for strong::-value::, it is possible to register any function (and thus any arbitrary code) for evaluation when Cmd-. is pressed.
13 Registers an object to be cleared when Cmd-. is pressed. This object will stay registered until it is explicitly removed, and will thus respond to additional presses of Cmd-.
16 Removes an object that was previously registered.
19 Removes all objects that have been registered.
22 Registers an object to be evaluated once, and then unregistered.
25 Get or set the list of objects that are called when CmdPeriod is evaluated.
28 The number of times CmdPeriod has been called since startup.
44 // Now press Cmd-. Only f executes
46 CmdPeriod.remove(f); // must explicitly cleanup
51 CmdPeriod.add(g); // one object is added only once.
52 CmdPeriod.add(g); // one object is added only once.
61 // note that often you want to automatically remove the function once it is evaluated
64 f = { "foo".postln; CmdPeriod.remove(f) };
69 CmdPeriod.doOnce { "foo".postln }
73 w = Window.new("close on cmd-.").front;
74 CmdPeriod.doOnce { w.close };
78 // in some cases you might need to defer the function by a short amount of time
79 a = { Synth(\default)};
81 CmdPeriod.add({{a.value}.defer(0.01)});