Applescript + Screen Sharing

Discussion in 'Mac Programming' started by Nneon, Nov 19, 2009.

  1. Nneon macrumors newbie

    Joined:
    Nov 19, 2009
    #1
    Hey,

    I'm currently trying to write a script to automatically connect to another computer on my local network.

    this is the script so far:
    Code:
    tell application "Screen Sharing"
    	activate
    	
    	tell application "System Events"
    		keystroke "kiryns-laptop.local"
    		keystroke return
    	end tell
    	
    end tell
    I was hoping someone could help me get applescript to select the radio button that says connect "by asking for permission" and then hit return.

    here's what it looks like:

    [​IMG]

    thanks in advance ;)
     
  2. Nneon thread starter macrumors newbie

    Joined:
    Nov 19, 2009
    #2
    I'm still after a solution for this if anyone is able to help?
     
  3. mysterytramp macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #3
    Do you have a file called "UIElementInspector.app" (I have it but for some reason I believe that it's pre-SL and has been discontinued). Run it and you'll get a windoid that will provide the proper nomenclature for radio buttons and other UI elements.

    it'll probably be "Select button 1"

    mt
     
  4. larkost macrumors 6502a

    Joined:
    Oct 13, 2007
    #4
    The better solution is to use a "vnc://" url. For example:

    vnc://kiryns-laptop.local

    I believe that you can even put in username/password and have those passed (but in the clear on the system... a bit dangerous on shared systems).
     
  5. Nneon thread starter macrumors newbie

    Joined:
    Nov 19, 2009
    #5
    I'm still having trouble trying to work this one out... my experience with applescript is extremely limited.

    I've tried adding:

    Code:
    delay 1
    select button 1
    and others like that but with no success.

    If someone knows what I need to write instead and could help me out that would be greatly appreciated.
     
  6. jbcandkc macrumors member

    Joined:
    Nov 1, 2006
    #6
  7. Nneon thread starter macrumors newbie

    Joined:
    Nov 19, 2009
    #7
    Thanks for the link but that's not really what I'm after.

    I just need someone to tell me what I need to write to select that first radio button.

    Everything I've tried so far doesn't want to work :(
     
  8. Nneon thread starter macrumors newbie

    Joined:
    Nov 19, 2009
    #8
    Solved

    @binaryassist from twitter was able to provide me with this solution for anyone else who may be interested.

    Code:
    tell application "System Events"
    click (radio button 1 of radio group 1 of window 1) of application process "NetAuthAgent"
    So my completed working AppleScript now looks like this:

    Code:
    tell application "Screen Sharing"
    	activate
    	
    	tell application "System Events"
    		keystroke "kiryns-laptop.local"
    		keystroke return
    		delay 1
    		tell application "System Events"
    			click (radio button 1 of radio group 1 of window 1) of application process "NetAuthAgent"
    			keystroke return
    		end tell
    	end tell
    	
    end tell
     
  9. AndreasFischlin macrumors newbie

    Joined:
    Apr 28, 2010
    #9
    There is a simpler and more elegant solution

    This works under Snow Leopard (Mac OS X 10.6.3):


    Code:
    (*
    
    	Purpose	Single command connection established to another Mac such as an AirBook
    	
    	Usage	Launch this script
    	
    			Upon first time use you are likely having to enter user name and password. To allow for even more convenient connecting check the checkbox "Remember this password in my keychain"
    
    			Set the preference targetMacsIPName to the IP name of the Mac to which you wish to connect.
    			
    			Note, the target Mac must have screen sharing enabled, choose menu command "Apple -> Systems Preferences... -> Sharing" and make sure checkbox "Screen Sharing" is checked)
    			
    	Programing	Andreas Fischlin, ETH Zurich, 28.Apr.2010 
    				http://www.sysecol.ethz.ch/staff/af/			
    
    *)
    
    property targetMacsIPName : "air-andreas.local"
    
    tell application "Screen Sharing"
    	open location "vnc://" & targetMacsIPName
    end tell
    
     
  10. Rick Sustek macrumors newbie

    Joined:
    Feb 3, 2011
    #10
    Also note, that you can launch the Screen Sharing app from a command line such as this:

    open vnc://TheOtherComputer.local

    The 'open' command knows what to do with that vnc URL, sending it to the Screen Sharing app.

    Now then, since this can be done, then you can also create an Automator program that simply runs that command in a shell script item. Create a few of these for all the computers in your realm, plop them on your desktop, and you've got easy point-and-click launching for your remote sessions.

    cheers,
    -Rick
     
  11. Rick Sustek macrumors newbie

    Joined:
    Feb 3, 2011
    #11
    also, easy desktop icon

    You can also make a simple launch icon the desktop without typing a thing:

    1) Establish an active screen share to some computer

    2) Drag the little title bar icon at the top of that window, to your desktop. It will automatically create a VNC link that can be then activated to launch a sharing session whenever you please.

    Not sure if this helps the OP, as it was not clear if he just wanted a simple way to launch a screen session to specific machines, or really needed something that was part of a larger AppleScript workflow.

    Cheers.
     

Share This Page