Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Local network messaging using AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Local network messaging using AppleScript
Authored by: sjmills on Feb 16, '05 09:29:33PM
There are plenty of reasons why someone would want to use a script such as this instead of iChat, email, Apple Remote Desktop, etc. Not everyone has ARD. To use iChat, it needs to be running on the source and dest machines. That means I'd have to run down the the basement or into the den to launch iChat, then run back, find that machine in iChat, and finally send the message. With mail, again, you have to launch it on the dest machine and wait for the mail to come in. On some machines, this might be a week's worth of mail being downloaded just to get the one you just sent. A script such as this is great because you only have to prepare the dest machines once (turning on Remote Apple Events), and because it's a cool little hack that a user can create on their own. I'm improving on the original by adding the ability for it to be a 2-way chat system for those times when that would be useful. I know I'm always needing to send serial numbers, url's, etc to another machine in the house and I hate writing stuff like that on paper when it's right in front of me and I can copy and paste it. I'd post my script, but Script Debugger is in one of its "I crashed once, so I'll just keep on crashing" moods, so I gotta reboot.

[ Reply to This | # ]
Local network messaging using AppleScript
Authored by: sjmills on Feb 16, '05 11:20:34PM
Here's my version. I chose to ask for the machine name by text instead of buttons because I have more than 3 machines I'll use this with. I also see nothing wrong with storing passwords in scripts that will only be used on my home machines. Besides, when I didn't have the username and password in the script, and I chose to store it in the keychain when it asked, it caused Script Debugger to crash during that run of the script and every time after that until I deleted that entry from my keychain.

Notice that the scripts finds the frontmost app on the remote machine instead of forcing it to the Finder. The weird thing is that the dlog comes up while the screensaver is running. Cool. Except using the Copy to Clipboard button in the screensaver causes an error, because that app is no longer running after the display dialog exists.

set msg to "Enter a message."

set dest to text returned of (display dialog "Enter the machine name to send a message to." default answer "Machine A" buttons {"Cancel", "OK"} default button "OK")

if dest is "Machine A" then
	set dest to "eppc://username:password@MachineA.local"
else if dest is "Machine B" then
	set dest to "eppc://username:password@MachineB.local"
end if

repeat while true
	--Get the msg to send. 1st time it's set above. After that it's the reply from the remote:
	set rep to (display dialog msg default answer "" buttons {"Copy to Clipboard", "Cancel", "Send"} default button "Send")
	
	if button returned of rep is "Copy to Clipboard" then
		set the clipboard to msg
		return
	end if
	
	set msg to text returned of rep
	
	--Figure out front app every time through loop in case it gets changed on the other machine:
	using terms from application "Finder"
		tell application "Finder" of machine dest
			set curApp to name of (item 1 of (every application process whose frontmost is true))
		end tell
	end using terms from
	
	--Send the msg and get any reply:
	tell application curApp of machine dest
		beep
		set rep to (display dialog msg default answer "" buttons {"Copy to Clipboard", "Cancel", "Send"} default button "Send" giving up after 30)
		
		if button returned of rep is "Copy to Clipboard" then
			set the clipboard to msg
			return
		end if
		
		set msg to text returned of rep
	end tell
	
	beep
end repeat


[ Reply to This | # ]
Local network messaging using AppleScript
Authored by: sjmills on Feb 16, '05 11:25:16PM

Ack. Sorry I didn't prewrap the script. I didn't know the [code] format would respect the line width.



[ Reply to This | # ]
Local network messaging using AppleScript
Authored by: Frederico on Feb 19, '05 11:11:19PM

Just a reminder from my earlier post: there is no need to run to another machine to launch iChat/email; as I pointed out, this would actually be a legitimate use of Remote Apple Events. IOW, you want to text message your buddy on the fifth floor, but his icon in iChat shows him offline; he has previously given you blanket permission to do so, so you remotely launch iChat and log him in on his machine so that he can then accept your message. If he's not there, your AppleScript dialog would fail just as readily.

Which also brings up another point: Without a dialog timeout (giving up after n), you may very well lock up some process on his machine if he is not there to dismiss it, and your own script engine will lockup until the default timeout, as well.

Again, I stress that with the exception of a very controlled environment (Yelling out: "Hey, Dave, I want to send you a text message, are you there and ready to accept it?" "Why don't you just tell me then?"), this script and its execution is going to be very problematic, and all the solutions you apply are already built into the installed system software. Why reinvent the wheel, except to show it can be done?

I'm all for people getting turned on to AppleScript, so if this hint serves that purpose, alone, more power to the OP.

Cheers



[ Reply to This | # ]
Launch iChat Remotely
Authored by: mrtoner on Jul 24, '06 09:37:00AM

Fairly trivial, really:

set machine_name to "eppc://workstation.local"
tell application "Finder" of machine machine_name
open item "Applications:iChat"
end tell

Note that the '.local' extension is easier than the IP address (which may change).



[ Reply to This | # ]