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 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 | # ]