There is no way to script I thing so I made pip for YouTube you can add this to trackpad or keyboard shortcut