A point of note.
If you need to use this script to recover the jobs from a restored copy of msdb that isn't named "msdb", you'll need to recreate/alter the system views dbo.sysjobs_view, and dbo.sysoriginatingservers_view to reflect the restored DB name.
rj