Script jobs offer another alternative to explicitly calling scripts, or pressing buttons, to invoke your functionality. By using script jobs, it is possible to trigger custom functionality based on either a specific condition or a specific event.
In this example, we'll create a script job that will respond to the selection changed event by printing the name and type of the selected object to the console.
One of the things that makes script jobs so useful is the fact that they persist (as opposed to just running once). However, that can make developing scripts that use them a bit difficult, since if you change your code and re-run your script, you'll end up with multiple script jobs in your scene. For that reason, it's good to give yourself a way to easily clear out all existing script jobs. The following script will do just that:
import maya.cmds as cmds def killAll(): cmds.scriptJob(killAll=True, force=True) print('KILLED...