Help capturing a portion of the screen

Hello, Command-Shift-4 will capture the selected portion of the screen on Mac.
How can I achieve that programmatically, (in code)?

Answered by Gavin here [How can I execute Command-Shift-4 from a Pushbutton? - #2 by Christian_Schmitz] … Thanks again Gavin

Thanks.

Lennox