 When Ambrosio O'Higgins died in 1801, Avilés was appointed viceroy of Peru.It took him eight years to remove O'Higgins's protégé Juan Mackenna from Osorno.In 1809 Juan Mackenna married Josefina Vicuña y Larraín, an eighteen-year-old Chilean woman from a family with revolutionary connections, with whom he had three children