Use Marco Polo or any of the alternatives described on that page to determine your location (change) and execute a shell script that edits
defaults write com.apple.screensaver askForPasswordDelay -int 1800
Unfortunately, this only takes hold after a re-login. But you can instead use AppleScript for GUI scripting your way through System Preferences:
tell application "System Preferences"
set current pane to pane id "com.apple.preference.security"
tell application "System Events"
tell process "System Preferences"
tell first window
tell first tab group
# ensure we're on the first tab
click (first radio button whose title is "General")
# 'require password' checkbox
set cb to (first checkbox whose title is "Require password")
# 'require password' popup button
set pb to pop up button 1
# always enable password
if value of cb is not 1 then
# password is currently disabled, enable it
# if password is activated now, set the timeout
# this check is redundant, you can remove it
if value of cb is 1 then
# click pop up button to get menu
click pop up button 1
# select 'immedately'
click first menu item of menu of pb
Create three versions of this script for each desired selection from the popup-menu.
first menu item is immediately,
second menu item is 5 seconds, and so on.
Save them as script, e.g.
immediately.scpt, and execute using
osascript from the command line, or save as application from AppleScript Editor, and execute by
Depends on which solution for determining your location you decide to use.