Screen Sharing with Alfred’s Help

Now that I’ve got a few Macs hanging around my house (I think they are breeding), and only the one monitor, I’ve been using the Screen Sharing capability of OS X a fair bit.  While this is a quite excellent little tool, it’s hidden away in the System/Library/CoreServices folder, rather than in Applications, so not what you’d call easy to find.  It can be kept in the dock, but my preference is to keep the dock fairly sparse, so I started using ScreenSharingMenulet, a quite nifty little program that sits in the menu bar and lets you choose what Mac you want to start screen sharing with.  This worked great till I started using Alfred – it seemed wrong to be unable to use this quite wonderful tool to fire up screen sharing.  So I dipped into AppleScript and created the following script (Zoidberg is the name of the Mac I want to screen share with)…

    tell application “Screen Sharing”
        activate

        tell application “System Events”
            keystrokeZoidberg.local
            keystroke return
        end tell
    end tell

Then I fired up the Extensions tab in Alfred Preferences, chose the AppleScript extension and gave it a name (Screen Sharing).  I then pasted the code above into the AppleScript text box and gave it the Alfred keyword of SSZoidberg, with the Background box checked.

And simple as that, I can start screen sharing with just a few Alfred keystrokes, no trackpad or mouse required.  Lovely!

11 comments

  1. Brian

    I can’t get this to work. If the computer I want to connect to has two words as part of it’s name, how do I type that into the script? I’ve tried putting it in quotes, replacing the space with %, etc.

  2. Alan

    For spaces, I think the default would be a dash, so eg “my-computer.local”. You should be able to see the full shared name by clicking on Screen Sharing on the Sharing menu in System Preferences…it will say something like “Computers on your local network can access your computer at: Zoidberg.local”.

  3. Brian

    That did the trick! This is awesome, thank you. I screenshare into my other computer multiple times a day this saves quite a few steps.

  4. Harrison

    I modified your script a bit to allow for entering the computer name to be entered as input rather than hardcoded.on alfred_script(q) tell application “Screen Sharing” activate tell application “System Events” keystroke q keystroke return end tell end tellend alfred_script

  5. kavehv

    Here’s a better script:on alfred_script(q) tell application “Screen Sharing” open location “vnc://” & q activate end tellend alfred_script

  6. Tom

    I’m not sure if this is a quirk of my network, or the norm, but I’ve found that connecting via IP address is substantially quicker than using a .local name.

  7. Pingback: Full Screen Screen Sharing via AppleScript & Alfred in Mountain Lion | Colin Harman

Leave a Reply