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

Local network messaging using AppleScript Network
As an office manager I was looking for a way to send my co-workers little messages over the network without using Mail or IM – without using any app for that matter. OS 9 did something like that using the built-in Sharing control panel (easter egg?), but OS X had nothing like that. Inspired by the Remote Apple Events hint, I wrote this script:
tell application "Finder"
  display dialog "Choose computer:" buttons ¬
    {"Workstation_1", "Workstation_2"} default button 2
  if the button returned of the result is "Workstation_1" then
    set machine_chosen to "eppc://Workstation_1:password@192.168.1.45"
  else
    set machine_chosen to "eppc://Workstation_2:password@192.168.1.46"
  end if
  display dialog "" default answer "How are you doing?" buttons ¬
    {"Cancel", "Send"} default button 2
  copy the result as list to {text_returned, button_pressed}
end tell

tell application "Finder" of machine machine_chosen
  activate
  beep
  display dialog text_returned buttons {"Cancel", "OK"} ¬
    default button 2 giving up after 30
  set the clipboard to the text_returned
end tell
To make this AppleScript work, activate Remote Apple Events in the Sharing preference pane on the machine you want to send a message to. Change the machine names, passwords, and IP's, save the script in the Scripts folder of your own machine, and send your message. The set the clipboard to the text_returned line I added to let the receiver use the text I send them, if they wish. They then paste the text anywhere they want.

Just to be secure: make sure your network security settings won't allow events from unknown IP numbers, and turn on the Firewall.
    •    
  • Currently 3.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[24,151 views]  

Local network messaging using AppleScript | 21 comments | Create New Account
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: ssevenup on Feb 15, '05 11:38:02AM
Just to be secure: make sure your network security settings won't allow events from unknown IP numbers, and turn on the Firewall.
This hint should really expand on what is involved in this last advice. Achieving the level of security suggested will require editing some files in /etc and probably a third party firewall (or at least overriding the simplistic level of security the GUI provides).

---
Mark Moorcroft
ELORET Corp. - NASA/Ames RC
Sys. Admin.

[ Reply to This | # ]

Local network messaging using AppleScript
Authored by: adrianm on Feb 15, '05 12:06:07PM

And putting a password in the script is not a particularly good idea.



[ Reply to This | # ]
Enabling and customizing OS X Firewall
Authored by: msk on Feb 16, '05 08:54:06AM

Enabling and customizing the OS X Firewall has been covered to death elsewhere.

For anyone who does not wish to create a startup item to enable a customized firewall, there are programs like Brickhouse which configure the firewall built into OS X, very likely some of those programs are free.



[ Reply to This | # ]
Local network messaging using AppleScript
Authored by: Beavix on Feb 15, '05 01:02:29PM

I use iChat Rendezvous for sending messages between the network computers. It's much much easier.



[ Reply to This | # ]
Local network messaging using AppleScript
Authored by: allanmarcus on Feb 15, '05 03:09:41PM

I'm not 100% certain, but I think both Mac OS X Server and Apple Remote Desktop have a way to pop a message up on people's computer.

I think the method suggested in the hint is quite complicated as opposed to just used iChat locally.



[ Reply to This | # ]
Local network messaging using AppleScript
Authored by: Miks on Feb 15, '05 07:14:53PM

I think that the Sharing part of the File Sharing control panel has been replaced, under 10.3 with the "Remote Apple Events" checkbox in the Sharing pane.



[ Reply to This | # ]
Local network messaging using AppleScript
Authored by: ppatoray on Feb 15, '05 08:19:35PM
I did something to achieve a similar goal, but using Pashua GUI for a php shell script saved in my scripts menu for easy access, and an ssh connection, so it can be used across any network pretty safely.

Oh yeah, best of all, mine uses the command 'say' to use the system voices to speak the messages, and you can choose the voice from a list. This might be a bit annoying in a work environment, but it's perfect for sending a quick message to my girlfriend who is working in another room.

I wrote up a quick how-to and put it up on my website for anyone that is interested: http://www.patrickpatoray.com/?Page=56

[ Reply to This | # ]
Local network messaging using AppleScript
Authored by: taxi on Feb 15, '05 10:00:32PM

Rather than just yelling it out?

Or better still, walking in there, giving her a kiss and then telling her...



[ Reply to This | # ]
Local network messaging using AppleScript
Authored by: Frederico on Feb 15, '05 10:30:38PM

Apart from the security issues as noted by other users, I have a few issues with this script as written that others might wish to be aware of.

First, there is no need to enter a password within the script; the user would be prompted for password on first run, and it can be added to the Keychain from there forward, where it will not ask again (unless the Keychain itself requires unlocking).

Second, I know I'd be pretty irritated to be switched out of whatever program I'm running to Finder just to find a text dialog with someone bothering me while I work; such a shift very well may botch an operation I'm in the middle of; at minimum it will interrupt my train of thought and is basically just plain rude behavior. If you must use this kind of script, best to use 'tell current application' or derive the frontmost app and tell it to display the dialog, so that at least the user is not ripped from their current program.

Third, I know I'd want to smack the message sender for messing with my clipboard, especially if I just spent most of five minutes shift-clicking a very difficult set of elements in Flash or AI and had pasted them to the clipboard, only to find my clipboard now contains 'How you doin'?' While it's possible in some bizarre work flow of the author's imagination, there is a reason to paste that text back somewhere else, best to add a button in the dialog that *optionally* pastes the incoming message to clipboard.

Finally, I'm with everyone else. For this script to work it has to be run on Macs which come with IM and email programs by default. Unless these apps have been removed or disabled for security reasons, they should be the carrier of intra-office communications, as they are already designed to accept messages and alert the user to said message without damaging the current work flow. If need be, an AppleScript can be run on the remote target to open iChat (or whatever) and set its status to available in order to accept the message.

Beyond that, yes, just use Apple Remote Desktop to send screen messages in a corporate environment.



[ Reply to This | # ]
Local network messaging using AppleScript
Authored by: d. on Feb 16, '05 03:30:14AM

@Beavix: I don't have a .Mac or AOL account to use with iChat, I presume you need that to activate iChat, unless somebody can telll me otherwise. That's why I wrote this script.

@Frederico: I admit that is very very annoying to be switched out of your current program jus to get a stupid message and then finding out that your clipboard is changed. An optional choice button to use the message in the clipboard also crossed my mind, but I needed this to work faster for my co-workers.

It's a bit silly how I use this script anyway. Before I send my message I warn my co-workers that a message is coming in. It's just a fast way for me to send then little bits of text which they can work with directly.

d.



[ Reply to This | # ]
Local network messaging using AppleScript
Authored by: d. on Feb 16, '05 04:08:52AM

AAAH! Forget my last remark about iChat, I feel like a ********, for some reason I never get passed the iChat register screen. To be precisely, I never pressed 'continue'...

What the **** was I thinking? Sometimes you look for solutions everywhere, in the strangest places, just to find out that the solution was allready there, around the corner.

Shame, shame.



[ Reply to This | # ]
Local network messaging using AppleScript
Authored by: osxpounder on Feb 16, '05 03:57:33PM

Hmm, I don't see the point of any of this effort, when your Mac comes to you with iChat. I'd be pretty angry at finding out my meticulously constructed selection just vanished from the Clipboard, too, and and I also agree that it's annoying to be "ripped out of your program" when you're busy with it. Heck, I don't even like it when other programs *I* chose to run do that to me -- I think it's very rude and disruptive of Mail, for example, to pop up on my screen while it's finishing its startup sequence and downloading my mail. I HATE that. That's what the Dock is for -- so a program can discreetly ask for attention by bouncing, rather than popping itself up between me and my work.

---
--
osxpounder



[ Reply to This | # ]
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 | # ]
Local network messaging using AppleScript
Authored by: squeeb on Jan 03, '06 01:41:19AM

Great .... except it doesn't work.
If you try and use Remote Apple Events you get the "No user interaction allowed" Message.
Shame.



[ Reply to This | # ]
With Mac OS X 10.4.7 it simply doesn't work
Authored by: XFox on Jul 05, '06 12:31:54AM
When I try to run the script on a Mac OS X Server 10.4.7 to communicate with a Mac OS X 10.4.7 client I get a "No user interaction allowed." error message right after the client machine's password dispatch.

[ Reply to This | # ]
With Mac OS X 10.4.7 it simply doesn't work
Authored by: d. on Jul 11, '06 03:50:44AM

Apparently user authentication or user interaction appears to have
changed in Tiger. I've been trying everything. What still does work is
sending a "do shell script" command to a remote machine.

Displaying a dialog to a remote machine (Tiger to remote Tiger)
doesn't work anymore. Tested it with Tiger to remote Panther, that
worked funny enough...

Since I'm not using this script anymore, I will not go into it deeper
then I allready have, but it still bugs me.



[ Reply to This | # ]
Local network messaging using AppleScript
Authored by: Binski on Jan 31, '11 01:31:34PM

d

I liked your script. I think there are good uses for it. Also it is just kind of fun playing around with.

Some folks had valid comments though. Yes, this script no longer works. I assume Apple restricts remote Apple Events for security reasons.

Frederico — Man, your a buzz kill!



[ Reply to This | # ]