Change UserPreferencesFilePaths using Python

Does anyone know how to change the script directory in the user preferences using Python from command line?

I believe it has something to do with bpy.types.UserPreferencesFilePaths, but I'm not sure how to use it.

import bpy
from bpy import context
path = "/somepath"
context.user_preferences.filepaths.script_directory = path

• thank you, that works for 2.77 and 2.78, have yet to try with 2.76, but my guess is it works for 2.76 as well – Chunlin Hu Nov 1 '16 at 8:46