Ok, this Lan IM is made from 3 script apps, 2 script files, 1 rtf file and 2 folders. But it’s good fun for chatting in lessons if possible.
First make a folder for it all and call it whatever you want. Inside, put another folder called Data and the following script (Save as an app under any name, this is what will run everything and send the messages) :
Property Datarg : (item 1 of (list disks)) as text
set defUsername to NameTemplate's dname
tell application "Finder"
set PTapp to (path to me)
set PTme to (((the container of (PTapp)) as alias) as string) & "Data:"
end tell
set Serv to ((datarg) as text) & "IM.scpt"
tell application "Finder" to open (PTme & "IM reciever.app") as alias
activate
set the_interface to 0
repeat
set ip_internal to ""
try
set ip_internal to do shell script ("ipconfig getifaddr en" & the_interface)
end try
if ip_internal is not "" then exit repeat
set the_interface to the_interface + 1
if the_interface = 5 then
set ip_internal to " unknown "
exit repeat
end if
end repeat
repeat
set message_out to (display dialog "Send: " default answer "" buttons {"New name", "Close", "OK"} default button "OK")
if the button returned of message_out is "New name" then
set defUsername to the text returned of (display dialog "Username:" default answer defUsername)
set NameTemplate's dname to defUsername
else if the button returned of message_out is "Close" then
set noff to load script (PTme & "IM offer.scpt") as alias
set noff's ONOFF to 1
store script noff in (PTme & "IM offer.scpt") replacing yes
tell application "TextEdit"
delay 1
quit without saving
end tell
exit repeat
else
set message_out to the text returned of message_out
set targ to load script (Serv) as alias
set targ's IMmessage to message_out
set targ's Sender to defUsername
set targ's NewIM to ip_internal
store script targ in (Serv) replacing yes
end if
end repeat
script NameTemplate
property dname : missing value
end script
Then, in the Data folder put the following:
1 RTF document caled base
1 script application that will do whatever you want done when you recieve a message called New Message (This will only run if you remove the (* and *) from the reciever app later in the instructions)
1 script called IM offer consisting of
property ONOFF : 0
and 1 script app called IM reciever consisting of
set datarg to "Macintosh HD" (* insert host's hard-drive name*)
tell application "TextEdit"
run
end tell
tell application "Finder"
set PTapp to (path to me)
set PTme to ((the container of (PTapp)) as alias) as string
end tell
tell application "TextEdit"
open (PTme & "base.rtf") as alias
end tell
set noff to (load script alias (PTme & "IM offer.scpt") as alias)
if noff's ONOFF is 1 then
set noff's ONOFF to 0
end if
set Serv to ((datarg) as text) & "IM.scpt"
set the_interface to 0
repeat
set ip_internal to ""
try
set ip_internal to do shell script ("ipconfig getifaddr en" & the_interface)
end try
if ip_internal is not "" then exit repeat
set the_interface to the_interface + 1
if the_interface = 5 then
set ip_internal to " unknown "
exit repeat
end if
end repeat
repeat
set noff to (load script alias (PTme & "IM offer.scpt") as alias)
tell application "TextEdit" to set pretext to the text of the front document
try
set message to (load script alias Serv as alias)
if noff's ONOFF is 1 then
set noff's ONOFF to 0
store script noff in (PTme & "IM offer.scpt") replacing yes
exit repeat
end if
set Sender to message's Sender
set NewIM to message's NewIM as text
set IMmessage to message's IMmessage
if Sender is "" then
else
if NewIM is ip_internal then
tell application "TextEdit"
set the text of the front document to (pretext & Sender & return & IMmessage & return & return) as text
end tell
delay 0.5
else
if RecTemplate's NMalert is 1 then
tell application "Finder"
open (PTme & "New Message.app") as alias
end tell
end if
tell application "TextEdit"
set the text of the front document to (pretext & Sender & return & IMmessage & return & return) as text
end tell
set targ to load script (Serv) as alias
set targ's IMmessage to ""
set targ's Sender to ""
set targ's NewIM to 0
store script targ in (Serv) replacing yes
end if
end if
set Sender to ""
set IMmessage to ""
set NewIM to ""
end try
end repeat
script RecTemplate
property NMalert : 0
end script
(Note the host’s harddrive name must be included instead of “Macintosh HD” on line 1)
Then, last but not least, the host computer, (The one who will be connected to) needs this script on his hard drive:
property NewIM : 0
property Sender : ""
property IMmessage : 0
Save it as IM
Done! Give the folder with the program in it to a friend and connect through filesharing as an admin user, mount the Hard drive and start the main applicaiton.
I’m working on a simplifyed one, but I doubt I’ll put it up. This one’s enough.
P.S. To change theme, modify the font and coloring of the ‘base.rtf’ file in data.
Model: MacBook 80 gig
AppleScript: 2.1.1
Browser: Safari 419.3
Operating System: Mac OS X (10.4)