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

Reverse Screen Sharing Grabber Network
I often need to (briefly) share my desktop with a room full of people, for example: to review drawings before printing. Since I dislike people standing behind me and staring over my shoulder, I wanted a way share my screen to a separate, public screen.

Ideally, the boss could say 'Put it on the big screen' and with one click I could be sharing -- all without anyone coming near my computer.

I work on a MacBook Pro, which is named 'W89100AK7AP.' In this case, I already had a big screen: the monitor attached to my Mac mini (named 'Dr-Cube' below) that spends the rest of the day as a jukebox.

Remotely starting Screen Sharing is easy. I saved the following line as GetScreenRemote.command and made it executable with chmod 755.
ssh Dr-Cube.local "osascript -e 'tell application "Screen Sharing" to open location "vnc://username:password@W89100AK7AP.local"'"
Dr-Cube (the mini) will be catching the screen from W89100AK7AP (the MacBook Pro with 'Remote Management' enabled). You'll need to change these to match the Bonjour names (or IP addresses) of your machines. The username:password does not have to be hardcoded into the script, I just wanted to make sure I was doing all the syntax correctly.

When run, the mini promptly grabs the screen of my computer and displays it, scaled to fit its own display. Sadly, there is no fullscreen Screen Sharing in Snow Leopard.

So far so good, but I want it run without asking for a password in terminal, so it's time to create an RSA Authentication Key between my computer and Dr Cube.

Note: I'm not really concerned about the security—even if someone actually wanted to control Dr-Cube, they'd only get access to my iTunes Library, there's nothing sensitive in it; as for my MacBook, it doesn't leave my sight.

Now, in the Terminal, type (pressing Enter after each of the commands to execute it):

ssh-keygen

which results in (you'll need to enter a name and location to save the resulting key file):
> Generating public/private rsa key pair.
> Enter file in which to save the key (~/.ssh/id_rsa): (enter)
> Enter passphrase (empty for no passphrase): (enter)
> Enter same passphrase again: (enter)
> Your identification has been saved in ~/.ssh/id_rsa.
> Your public key has been saved in ~/.ssh/id_rsa.pub.
> The key fingerprint is: (fingerprint)
> The key's randomart image is: (randomart)
then type:

mkdir /Volumes/dr-cube/.ssh

finally:

cp ~/.ssh/id_rsa.pub /Volumes/dr-cube/.ssh/authorized_keys

Again make sure to substitute the name of your Mac for dr-cube. Now the command runs without asking for a password.

One last step: I want it to run without even opening a terminal window. So I dropped the 'GetScreenRemote.command' into a standard location, and made a small AppleScript.

Enter the following into the AppleScript Editor:

do shell script "/Library/Scripts/GetScreenRemote.command"

Save As ScreenSender.app with File Format: Application, and we're done.

Now, with one click I can tell the mini to grab and display my screen!

Note: This is a single afternoon's worth of solution, and is not perfect. Ideally, the GetScreenRemote.command would switch itself on or off with each run, maybe using something based on this pseudocode:
if "ps ax | grep Screen Sharing | grep -v grep | awk '{print $1}'")  is "[no process]" then
ssh Dr-Cube.local "osascript -e 'tell application "Screen Sharing" to open location "vnc://username:password@W89100AK7AP.local"'"
else "kill -9 Screen Sharing"


[crarko adds: I tested most of this, and it works as described. If something breaks make sure you have changed the machine names to correctly match yours. Also note that leaving username:password as is will cause Screen Sharing to put up the login prompt, so you really don't have to hard code these in the script.]
    •    
  • Currently 3.50 / 5
  You rated: 3 / 5 (8 votes cast)
 
[12,157 views]  

Reverse Screen Sharing Grabber | 14 comments | Create New Account
Click here to return to the 'Reverse Screen Sharing Grabber' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Reverse Screen Sharing Grabber
Authored by: lras on Dec 03, '10 08:01:21AM
No need to use applescript, just use "open"...

ssh Dr-Cube.local open vnc://username:password@W89100AK7AP.local


[ Reply to This | # ]
Reverse Screen Sharing Grabber
Authored by: capacity on Dec 03, '10 08:19:19AM
Just to be cautious (and hey, I'm not an expert in this stuff), it seems to me that:

cp ~/.ssh/id_rsa.pub /Volumes/dr-cube/.ssh/authorized_keys

should be:

cat ~/.ssh/id_rsa.pub >> /Volumes/dr-cube/.ssh/authorized_keys

so you don't overwrite anything that's in authorized_keys if that file already happens to exist.

[ Reply to This | # ]
Reverse Screen Sharing Grabber
Authored by: auntchilada on Dec 03, '10 08:36:07AM

uh, your hostname is your kit's serial number? obtuse and uncool?

http://www.appleserialnumberinfo.com



[ Reply to This | # ]
Reverse Screen Sharing Grabber
Authored by: donmoemu on Dec 03, '10 12:23:14PM

MacBook Pro (17-inch, Early 2009) nice machine



[ Reply to This | # ]
Reverse Screen Sharing Grabber
Authored by: aechadwick on Dec 03, '10 02:37:58PM

honestly, does this open me to any sort of security problem? or do you simply disapprove of my lack of imagination?



[ Reply to This | # ]
Reverse Screen Sharing Grabber
Authored by: mbenchoff on Dec 03, '10 05:47:41PM

Quite possibly that's the name given to his Mac by his IT department. We tag all of our equipment with unique numbers which makes inventory and remote management easier. People can try to change their computer name, but it reverts back to our name upon logout.

Oh yeah, and cool hint!



[ Reply to This | # ]
Reverse Screen Sharing Grabber
Authored by: bschoate on Dec 03, '10 09:21:15AM

If you're not averse to installing SIMBL, Megazoomer lets you take Screen Sharing full-screen (and works with Snow Leopard).



[ Reply to This | # ]
Reverse Screen Sharing Grabber
Authored by: Asmus Vierck on Dec 03, '10 10:47:09AM
I'm not really concerned about the security—even if someone actually wanted to control Dr-Cube, they'd only get access to my iTunes Library, there's nothing sensitive in it; as for my MacBook, it doesn't leave my sight.

You do realize that you are giving away your MacBooks username and password in plain text to Dr-Cube, right?! At least use could use the Keychain for that! Also, files that reside in /Library/Scripts are also available to every user on your computer!
Seriosly, please consider using: ssh username@dr-cube.local open vnc://username:password@macbook.local as it does what you need without giving away security.

[ Reply to This | # ]
Reverse Screen Sharing Grabber
Authored by: Anonymous on Dec 06, '10 10:09:45AM

Indeed.

"there's nothing sensitive in it"
Yes there is: local user access and a CPU... I bet it's still a member of "wheel", so "sudo -s" would get you a root shell. Hello keylogger on your *MacBook*.

"as for my MacBook, it doesn't leave my sight. "
Until the next fire drill, eh?



[ Reply to This | # ]
Reverse Screen Sharing Grabber
Authored by: aechadwick on Dec 06, '10 10:28:56AM
I've attempted to incorporate security concerns, but my abilities are modest--that why I was so excited by this little achievement in the first place.

If you want to contribute code, that would be awesome.
Edited on Dec 06, '10 10:30:07AM by aechadwick


[ Reply to This | # ]
Reverse Screen Sharing Grabber
Authored by: aechadwick on Dec 03, '10 02:36:04PM
I'm the submitter. I spent more time with this the next day, and got it down a little simpler.

on Dr Cube, this Applescript:

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://username:password@W89100AK7AP.local"
end if

saved as "ScreenSharingSwitch.app"

when triggered, this scans processes—if Screen Sharing is already running, it terminate the process; if Screen Sharing is not running, it grabs W89100AK7AP's screen. Thus, one call to start, or one call to stop.
on my W89100AK7AP, this Applescript:

do shell script "ssh Dr-Cube.local \"open /Library/Scripts/ScreenSharingSwitch.app\""

saved as "ScreenSharingSender.app"

this sends the call to Dr Cube to run the above script, superseding the previous .command-and-do-shell version.

*previous instructions already established the secure ssh key.

[ Reply to This | # ]
Reverse Screen Sharing Grabber
Authored by: aechadwick on Dec 04, '10 08:03:47AM
Asmus Vierck introduced the idea of using Keychain, an excellent point!

I made a new Keychain Item on Dr Cube named "ScreenSharingGrabber" (don't be mean, I just like to keep things simple)

then on Dr Cube, here is the most up-to-date version of the Applescript (v.3 at this point!)

tell application "Keychain Scripting"
	tell keychain 1
		unlock
		set theKey to first key whose name is "ScreenSharingGrabber"
		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 & "@W89100AK7AP.local"
end if
saved as "ScreenSharingSwitch.app"

I have been trying to keep this to free & built-in components. (I actually tried Remote Desktop via one of the work machines, but I could not automate "fullscreen," it always appeared as a window—the window had a "make fullscreen" button, but I could not find a term in Remote Desktop's AppleScript dictionary.)

My other goal is one-click operation—that's why the use of ApplecScript to make all the system calls. If operation isn't instant and foolproof, the effect is lost—and then I'm surrounded by people staring over my shoulder—only now they're slightly frustrated, because I failed at being clever!

[ Reply to This | # ]
Reverse Screen Sharing Grabber
Authored by: chucky23 on Dec 04, '10 06:38:13AM

FWIW, there is a built in command in Apple Remote Desktop to easily accomplish this task without the security shenanigans.

I understand that ARD is somewhat pricey, but I thought I ought to mention it here..



[ Reply to This | # ]
Reverse Screen Sharing Grabber
Authored by: aechadwick on Dec 27, '10 09:00:49AM
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 (any) Catcher save this AppleScript as a compiled script " SceenSharingSwitch.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 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!
Edited on Dec 27, '10 09:03:00AM by aechadwick


[ Reply to This | # ]