AppleScript to change resolution as done via System preferences: Displays: Display: Resolution: Scaled.
Note: I am not the author of this script. I retrieved it after searching on Google and saved it here so a trace is kept but I am not and don't know the author of this script.