import bpy

script_dir = u'__SCRIPTS__'
if bpy.app.version < (2, 80, 0):
    bpy.context.user_preferences.filepaths.script_directory = script_dir
    bpy.ops.wm.save_userpref()
else:
    bpy.context.preferences.filepaths.script_directory = script_dir
    bpy.ops.wm.save_userpref()
