How can I set the volume level?

You can use Standard Additions’ command set volume. Since AppleScript 1.9.4 the syntax is the following:

set volume output volume 75 --> number from 0 to 100

You can also specify “input volume”, “alert volume”, or mute the sound using the “output muted” parameter.

Previously, the syntax was “set volume 5” (from 0 to 7).

And, in past operative systems, you can use Jon’s Commandsset sound volume to command.