OK, here you go.
As you can see there's a lot of delays and some steps are done twice. I found scripting wifi to be a bit of a pain, since the network preferences window can act in rather unpredictable ways, depending on the circumstances (how were you connected, how many known networks are in range, etc etc). So, it's a rather messy script.
There's a good chance this will need some tweaks to work (especially if you're on a different OS; I'm on Mountain Lion).
Good luck!
property NetworkName : "adhocnet"
property NetworkPassword : "7654321qwerty"
property StaticAddress : "192.168.100.1"
property SubMask : "255.255.255.0"
tell application "System Preferences"
activate
set current pane to pane id "com.apple.preference.network"
end tell
--this part to turn wifi on (if necessary) and select the wifi tab in the network window
tell application "System Events"
tell application process "System Preferences"
tell window "network"
repeat with theRow from 1 to 4
if name of static text of row theRow of table 1 of scroll area 1 is {"Wi-Fi, Off"} then
select row theRow of table 1 of scroll area 1
tell group 1
click button 1
delay 4.0
end tell
exit repeat
end if
if name of static text of row theRow of table 1 of scroll area 1 is {"Wi-Fi, Connected"} then
select row theRow of table 1 of scroll area 1
delay 2.0
exit repeat
end if
if name of static text of row theRow of table 1 of scroll area 1 is {"Wi-Fi, On"} then
select row theRow of table 1 of scroll area 1
delay 2.0
exit repeat
end if
end repeat
--this part to set manual IP address for wifi
click button "Advanced…"
delay 0.5
tell tab group 1 of sheet 1
click radio button "TCP/IP"
delay 0.5
click pop up button 1
delay 0.5
click menu item "Manually" of menu 1 of pop up button 1
delay 0.5
set value of text field 3 to SubMask
set value of text field 2 to StaticAddress
delay 1.0
end tell
tell sheet 1
click button "OK"
delay 0.5
end tell
click button "Apply"
delay 1.0
end tell
--this part to select wifi tab again (sometimes it gets deselected)
tell window "Network"
repeat with theRow from 1 to 4
if name of static text of row theRow of table 1 of scroll area 1 is {"Wi-Fi, Off"} then
select row theRow of table 1 of scroll area 1
tell group 1
click button 1
delay 1.0
end tell
exit repeat
end if
if name of static text of row theRow of table 1 of scroll area 1 is {"Wi-Fi, Connected"} then
select row theRow of table 1 of scroll area 1
delay 0.5
exit repeat
end if
if name of static text of row theRow of table 1 of scroll area 1 is {"Wi-Fi, On"} then
select row theRow of table 1 of scroll area 1
delay 0.5
exit repeat
end if
end repeat
--this part to create an ad-hoc network with 128 bit WEP encryption
tell group 1
click pop up button "Network Name:"
delay 1.0
key code 121
keystroke return
end tell
end tell
repeat until exists window 1
delay 0.5
end repeat
tell window 1
delay 1.0
click pop up button 2
delay 0.5
click menu item 4 of menu 1 of pop up button 2
delay 0.5
set value of text field 3 to NetworkPassword
set value of text field 2 to NetworkPassword
set value of text field 1 to NetworkName
click button "Create"
delay 4.0
end tell
--this part to again manually set IP address (in case it got changed back)
tell window "network"
click button "Advanced…"
delay 1.0
tell tab group 1 of sheet 1
click radio button "TCP/IP"
delay 0.5
click pop up button 1
delay 0.5
click menu item "Manually" of menu 1 of pop up button 1
delay 0.5
set value of text field 3 to SubMask
set value of text field 2 to StaticAddress
delay 1.0
end tell
tell sheet 1
click button "OK"
delay 0.5
end tell
click button "Apply"
delay 1.0
end tell
end tell
end tell
tell application "System Preferences"
quit
end tell