Screen Sharing Grabber & Sender

I work in a studio where several people often need to briefly share information with the entire room”like to review drawings or graphics before printing or rendering.

Rather than gathering around everyone’s individual monitors, I wanted a way to send video to another, communal screen.

Our studio includes a mac mini that spends the rest of the day as a server and jukebox; the mini has a big screen attached, perfectly positioned for viewing by the entire room.

I wrote this pair of scripts to make a “reverse screen sharing grabber.” Now when someone says “put it on the big screen,” a script on my computer activates screen sharing on the mini, which in turn sends a call to grab my screen.

For this setup, we we will call the computers Sender1 (bonjour name sender1.local) and Catcher (bonjour name catcher.local)

To keep my Sender1’s password available, but hidden, I put it in a Keychain Item on Catcher, using the bonjour name of the computer. (/Applications/Utilities/Keychain Access.app, File > New Password Item…)

on Catcher, i saved this Applescript as “ScreenSharingSwitch.app


tell application "Keychain Scripting"
	tell keychain 1
		unlock
		set theKey to first key whose name is "Sender1.local"
		set theUsername to (account of theKey) as string
		set thePassword to (password of theKey) as string
	end tell
end tell

if application "Screen Sharing" is running then
	
	do shell script "ps ax | grep " & (quoted form of "Screen Sharing") & " | grep -v grep | awk '{print $1}' | xargs kill -9"
	
else
	tell application "Screen Sharing" to open location "vnc://" & theUsername & ":" & thePassword & "Sender1.local"
end if

when triggered, the script scans processes on Catcher”if Screen Sharing is already running, it terminates the process; if Screen Sharing is not running, it grabs Sender1’s screen. Thus, one call to start, or one call to stop.

I put ScreenSharingSwitch.app in /Library/Scripts so it could be available to all users.

on Sender1, I saved this Applescript as “ScreenSharingSender.app


do shell script "ssh catcher.local \"open /Library/Scripts/ScreenSharingSwitch.app\""

this sends the call to Catcher to run ScreenSharingSwitch.app.

Finally, I want ScreenSharingSender.app to run without asking for a password in terminal, so I created an RSA Authentication Key between Sender1 and Catcher.

on Sender1, I mounted Catcher as a network volume.

Then in Terminal:

then:

finally, I copied the RSA key to Catcher:

Now the command runs without asking for a password.

This set-up is effective, but the scripts only work between one pair of computers.

It would be better if ScreenSharingSender.app could run from any computer, like Sender2, Sender3, etc., which could simply identify itself when making the call, something like…

set theHostname to do shell script “hostname”
do shell script “ssh catcher.local "open /Library/Scripts/ScreenSharingSwitch.app"” [+ pipe theHostname to Catcher]

then pass that to ScreenSharingSwitch.app as part of the open location.

tell application “Screen Sharing” to open location “vnc://” & theUsername & “:” & thePassword & theHostname

but I have reached the limits of my ability for today, and I would love any input from the community.

Thanks for reading!!

Here is the most revised version of the Screen Sharing Grabber suite. For this setup, we will call the computers Sender1 (bonjour name sender1.local) and Catcher (bonjour name catcher.local)

on i[/i] Catcher save this AppleScript as a compiled scriptSceenSharingSwitch.scpt(save in location /Library/Scripts/ScreenSharingSwitch.scpt, or edit the sender script, below, to call correctly!)

on run argv

set theHostname to item 1 of argv

tell application "Keychain Scripting"

tell keychain 1
unlock
set theKey to first key whose name is theHostname
set {theUsername, thePassword} to {((account of theKey) as string), ((password of theKey) as string)}
end tell

end tell

if application "Screen Sharing" is running then
do shell script "ps ax | grep " & (quoted form of "Screen Sharing") & " | grep -v grep | awk '{print $1}' | xargs kill -9"
else
tell application "Screen Sharing" to open location "vnc://" & theUsername & ":" & thePassword & "@" & theHostname
end if

end run

the argv passes the hostname from the sending computer, as provided by the next script. Thus, it can work from Sender2 , Sender3 , or any computer. (Of course, this assumes physical access to each computer, as well as the administrator ability to set up an RSA key and “always allow” the Keychain.)

on each sender, save this Applescript as “SendScreenTo catcher.app”, replacing “catcher” with the localname of the grabber-host computer”this revised app will pull the localname from its own applet name”revise as required for any number of catchers.

tell application "Finder" to set catcherName to (last item of my text_to_list(first item of my text_to_list(name of (path to me) as Unicode text, "."), " ") & ".local")
--assumes name of Applet is "SendTo localname.app", will extract/concatenate "localname.local"

set theHostname to do shell script "hostname"

do shell script "ssh " & catcherName & " osascript /Library/Scripts/ScreenSharingSwitch.scpt " & theHostname

on text_to_list(txt, delim)
set saveD to AppleScript's text item delimiters
set AppleScript's text item delimiters to {delim}
set theList to every text item of txt
set AppleScript's text item delimiters to saveD
return (theList)
end text_to_list

Note, these scripts have no error trapping”they assume the existence of the appropriate Keychain, and an RSA key for SSH… basically, the scripts pretty much just assume everything will work.

thanks for reading!

Model: MacBookPro5,2 & Macmini4,1
Browser: Safari 533.19.4
Operating System: Mac OS X (10.6)

I know this isn’t code, but if you want a good, lightweight, and very simple way to share screens, check out ShowTime. It’s a really easy to use and well made application. Give it a try, it may save you lots of time and energy.

Good luck! :slight_smile:

That looks like a neat little app, I will take a look. It certainly is a cool solution to sharing screens quickly and easily!

“Showtime” isn’t really doing the same thing as these scripts, though… what I’m attempting to perfect is a one-click solution for multiple people to automatically send video to a dedicated video server, the “catcher,” like to demo graphics or other visual mock-ups.

Thank you for the contribution!!

Browser: Safari 533.19.4
Operating System: Mac OS X (10.6)