I think there are a few ways...
Here's a terminal script for logging off:
http://www.macosxhints.com/article.php?story=20031102031045417
There's the "shutdown -h" command that can be used to shutdown from terminal (you need to use sudo at the start then enter your password though)
Another lock screen applescript:
Open script editor and save it as an 'application' on your desktop.
set normalCommand to "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -suspend"
set theQuestion to "Do you really want to lock the screen?"
set theAnswer to button returned of (display dialog theQuestion buttons {"OK", "Cancel"} default button "Cancel" with icon note)
if theAnswer is "OK" then
do shell script normalCommand
end if
Just google something like 'shutdown shell script mac
Edit: Just use Quicksilver's scripts , they work great

See the attached files. You'll need to open them in Script Editor and save them as apps...I think