How to add operator and email notification on all the SQL jobs?

To be more proactive and responsive to the job issues or failures I want to set an alert, add operator and send the notification(to me) when a job fails. I know Operator and notification can be added through SSMS GUI but its a very time-consuming process and can be prone to errors so I am trying to do it through scripting. The following script gives me jobs

USE msdb SELECT AS JobName,     CASE     WHEN sj.enabled = 1 THEN 'Enable'     ELSE 'Disable'     END AS JobStatus,     sj.description AS JobDescription, AS JobScheduleName,     CASE     WHEN ss.enabled = 1 THEN 'Enable'     WHEN ss.enabled = 0 THEN 'Disable'     ELSE 'Not Schedule'     END AS JobScheduleStatus,      --ss.active_start_date AS ActiveStartDate,     --ss.active_end_date AS ActiveEndDate,     --ss.active_start_time AS ActiveStartTime,     --ss.active_end_time AS ActiveEndTime,     sh.step_name AS StepName,     Case         sh.run_status WHEN 0 THEN 'Failed'        WHEN 1 THEN 'Success'        WHEN 2 THEN 'Retry'        WHEN 3 THEN 'Canceled'        WHEN 4 THEN 'In Progress' END AS Status,     dbo.agent_datetime(run_date, run_time) As Last_Run_DateTime,     sh.run_duration AS RunDuration,      ((run_duration/10000*3600 + (run_duration/100)%100*60 + run_duration%100 + 31) / 60) as 'RunDurationMinutes' FROM dbo.sysjobs AS sj LEFT JOIN dbo.sysjobschedules AS sjs ON sj.job_id = sjs.job_id LEFT JOIN dbo.sysschedules AS ss ON sjs.schedule_id = ss.schedule_id LEFT JOIN dbo.sysjobhistory AS sh ON sj.job_id = sh.job_id 

I also made an attempt in adding operator, please correct me if I am doing it wrong.

DECLARE @Operator varchar(50) SET @Operator = 'Emamr' SELECT  sj.job_id AS JobID, AS JobName,         sj.description AS JobDescription,         ----adding operator using SP----        'EXEC sp_update_job @job_name = ''' + sj.[name] +         ''', @notify_email_operator_name = ''' + @Operator  +        ''', @notify_level_email = 2' As OperatorAdded  -- 1 = On Success, 2 = On Failure,3=always FROM dbo.sysjobs sj WHERE sj.enabled = 1  AND sj.notify_level_email <> 1 

After adding the operator I need to set an email notification and I don’t know how to do that in one script. Any help or guidance will be appreciated