Monday, November 5, 2007

Applescript - Automatically Accept iChat Share Screen Request

So we have been having tons of issues trying to get remote desktop to work properly on our network at the office. Nothing seemed to work. After upgrading to Leopard (sweet) and playing with the amazing new features in iChat, we started debating ways we could get iChat to work as a pseudo remote desktop.

I figured a simple Applescript would work well, but didn't realize how simple it would be. Apple has added iChat events into their preferences. You can select any of their preset scripts or create your own. So after some experimentation I created the following scripts to use. Just setup your audio invitation event to use the following applescript on the computer you want to control. Follow the instructions below...

1) Open Script Editor and copy the code below. You'll want to edit the email address in the code (in two areas) to whatever account you will be using to login to that computer.

Requirements : iChat for Mac OS X ver. 10.5 Leopard

(*

File: Auto Screenshare Accept.applescript


Abstract: An update of Apple's Auto Accept script to allow for automatic screenshare acceptance from a specific buddy. Also added is auto video chat acceptance which can act as a remote monitoring option so you can spy on people at work....home....wherever.

Version: 1.0


Disclaimer: IMPORTANT: I am not liable for any use of this script. Obviously, there are significant security risks to automatically enabling screen sharing. Do not use this script if you are unaware of or refuse to take responsibility for any potential security issues.


Created By: Graydon Stoner

http://www.getstonered.com


*)


using terms from application "iChat"

on received video invitation theText from theBuddy for theChat

set buddySN to (get name of theBuddy)

set allowedBuddy to "youremail@mac.com"

if (buddySN is allowedBuddy) then

if (screen sharing of theChat is local screen) then

accept theChat

end if

end if

end received video invitation

on received audio invitation theText from theBuddy for theChat

set buddySN to (get name of theBuddy)

set allowedBuddy to "youremail@mac.com"

if (buddySN is allowedBuddy) then

if (screen sharing of theChat is local screen) then

accept theChat

end if

end if

end received audio invitation

end using terms from



2) Save Applescript to ~user/Library/Scripts/iChat folder. If this folder isn't present you can either create it or open up iChat preferences, go to Alerts, check Run Applescript and select choose script and iChat will create it for you.

3) In iChat preferences, go to Alerts, select Audio Invitation event (screen share is a property of the Audio Invitation class), check Run Applescript, and choose the script you just saved.

4) Rock it out.

P.S. Also included is auto accepting video chats which I thought might be useful if you want to spy on anyone who might be at your computer. I'm sure there are lots of other useful uses as well. Keep me posted on what you come up with.

42 comments:

Anonymous said...

stumbled across this. does this work for aim accounts? if so do you just use the aim username and also how should I save the script? as an application or a script? thanks a lot.

Graydon Stoner said...

I believe this should work as long as both computer's are using Leopard's version of iChat. Otherwise I would doubt it would work for you.

Anonymous said...

it also works with googletalk accounts, which is nice since i believe they use a bit more security than the basic aim or ichat account. full .mac accounts have good security, but as far as i understand, an unpaid .mac name will not. i was looking at doing this myself, so thanks for saving me the trouble.

Anonymous said...

You are a genius!

Anonymous said...

This is a brilliant little script thanks so much for posting it. I have one question, is there a way to authorize more than one account with this script? Thanks!

Graydon Stoner said...

I've posted an update allowing a check of more than one account. Hope this helps out anyone who needs the added functionality.

Anonymous said...

I feel like an idiot after trying to get this script working. I am so sorry to be such a pain but please help me get it going, someone!

I was confused by the way to personalize it and I tried everything that made any sense with now success.

when you say to replace the email address in two places, what email address are you talking about? I use iChat with my AIM screen names not a .mac account. Also, is that the only two place the script needs to be modified and do I leave the quotations or remove them?

Graydon Stoner said...

Just replace the sample .Mac email address (youremail@mac.com) with your AIM username in both areas listed in the script (keep the quotation marks).

Then, follow the rest of the instructions to save your script and add it to an iChat event in your preferences. As long as both computers run iChat Leopard you should be fine.

Anonymous said...

Wow, works a treat, thankyou. didn't show up first attempt but second attempt worked well.

Anonymous said...

Hi, thank you for posting this I think its great idea and ScreensSharing works much better than CoVNC. But I am having a problem after saving your script to designated folder as "Script" using Script Editor and then selecting the file I just saved within iChat, when I launch iChat I get the following error:

An error occurred while executing an AppleScript event handler.

Event: When I Log In
File: Auto Screenshare Accept.scpt
Error: Error -1708

Now I don't know if this is because I saved the file with extension .scpt or what? I tried to find something that would save it as .applescript but did not know how to do that within Script Editor.

Your help is much appreciated.

Anonymous said...

Chax has a setting where you can auto accept the invites.

Graydon Stoner said...

You shouldn't have any issues saving the script with extension .applescript - Without the extension I don't think iChat will recognize it as a valid script to use for any event. I would try saving it again but adding the .applescript extension manually, rather than having Apple's Script Editor automatically adding the extension.

Hope that helps.

Anonymous said...

what do you do if you are away from the host computer and ichat logs out and doesn't log back in automatically (which it doesn't), are you stuck without a remote desktop? I am also getting the same error as above

Anonymous said...

Another way to share is via an application called Chatter (yep, I am the author - just spreading the word!). Its available from Shinywhitebox and lets you share any part of your desktop via the iChat AV Theatre mode. Maybe you find it useful.

ahead said...

This is awesome- thanks. I was thinking about this on my way home last night. I knew Leopard made the auto-accept scripts available, but then I thought, "it would be perfect if I could make one that worked for screen-sharing and would only accept a specific user." And here it is.

There was another tip on another site that was helpful too- and I thought I'd share here. If it's a work/ home/ remote machine you're trying to access, set up a specific chat address for that machine and log it in (won't work if both are on the same AIM address (or gtalk or jabber, whatever). Also, be sure to set the machine you want to access to never go to sleep.

Thanks again!

Anonymous said...

I have tried the suggestions above, but I still get the error message 1708. How do I manually change the file to .applescript?

Thanks!

Anonymous said...

You, sir, are a steely-eyed Mac man. Thanks for a script that allows me access to a server that I was having an impossible time getting VNC and ARD working with.

Anders Bäckman said...

I'm also getting Error -1708 and I've tried lots of things (including changing the file-extension) without any sucess to get this script working.

Help please? :(

ahead said...

I'm loving this script and it's working great for me- is there a way to set the receiving machine to automatically mute as well?

ahead said...

Nevermind my request to get it to mute- I figured it out. I put in a command just after "on received audio invitation theText from theBuddy for theChat" that reads:

tell application "Finder"
set volume 0
end tell

Works great!

Anonymous said...

I think your script is brilliant, and it has overcome many hours of frustration trying to get back to my mac to work.

But disaster has struck as the latest Leopard update 10.5.2 appears to have stopped it working. Do you know what Apple have done to cause this problem and can you fix it. Remote computer cancelled the connection (have tried both ways) and error message as follows:

2008-02-12 23:24:56 +0000: State change from AVChatStateConnecting to AVChatStateEnded.
2008-02-12 23:24:56 +0000: Error -7 (REMOTE cancelled the connection.)

Many thanks.

Tom

vimanaboy said...
This comment has been removed by the author.
Anonymous said...

This is really cool and helped me with some people not so computer savvy.

I have had no issues under the latest Leopard 10.5.2

vimanaboy said...

i got it working! i think it was a stupid user error on my part: i was trying to initiate a video chat (which does NOT work, at least for me) chalk it up to an ichat n00b ;)

thanks so much for this awesome script.

Anonymous said...

Wow, this great, exactly what I needed. Many thanks for posting it. Generous people, like yourself, regularly restore my faith in humanity.

Anonymous said...

I get this....

File: ichat automatic accept.scpt
Error: Error -1708

Anonymous said...

This is a great solution and we got it working for AIM, but the lines that define the allowed buddy are unnecessary. Instead of setting the script in the iChat main preferences, you can set actions on a per buddy level. Just control-click (or right click) on the buddy you want to allow and then choose Show Info, then the Alerts tab) to set the script to be allowed for only that buddy.
Also remove both instances of these 4 lines from the script:
set buddySN to (get name of theBuddy)
set allowedBuddy to "youremail@mac.com"
if (buddySN is allowedBuddy) then
end if

So now it is:

using terms from application "iChat"
on received video invitation theText from theBuddy for theChat
if (screen sharing of theChat is local screen) then
accept theChat
end if
end received video invitation
on received audio invitation theText from theBuddy for theChat
if (screen sharing of theChat is local screen) then
accept theChat
end if
end received audio invitation
end using terms from

Mark H. said...

Hi--I love this script, so elegant! I still get the 1708 error mentioned above. Did anyone figure this out? I'm stumped

Anonymous said...

Loved these scripts, but I'm getting that silly error as well with recent updates. Anyone have an idea?

Event: When I Log In
File: Auto Screenshare Accept.scpt
Error: Error -1708

Anonymous said...

You have no idea how incredibly helpful this script is for me! I couldn't figure out Apple Remote Desktop over IP and this is a lifesaver!!!

You are the MAN!

Do you have a donate button so i can buy you a beer?

Unknown said...

This script is great. Does anyone know how to script this so the video chat window automatically goes full screen after the chat is accepted?

Anonymous said...

This is very cool, you deserve a medal for this.

Anonymous said...

love the script, using for a kids computer in the house... i can get it to work through the "aim buddy list", but not locally through the "bonjour list". what settings do i have to change. thanks in advance.

Matt said...
This comment has been removed by the author.
Matt said...

If you want to use bonjour accounts with this auto accept script just put the bonjour address of the user you want to have auto access in place of the "yourmail@mac.com" within the script.

You can find out the bonjour address of a user by hovering your mouse over the user in the bonjour buddy list, a small info pop-up will show the details and should be in a format that look something like "username@computername".

Waleed Alzuhair said...

Hi,

I've recently bought a Mac mini to use as my home media center and your script made my life so much easier.. By auto accepting screen sharing, I can now easily manage the mini from my MacBook..

Thank you VERY much for your wonderful effort..

Kind regards,
Waleed Alzuhair
Riyadh, Saudi Arabia

Anonymous said...

I can't seem to get this to work.. any ideas? I set the events correctly.. I've even tried:

using terms from application "iChat"
on received video invitation theText from theBuddy for theChat
if (screen sharing of theChat is local screen) then
accept theChat
end if
end received video invitation
on received audio invitation theText from theBuddy for theChat
if (screen sharing of theChat is local screen) then
accept theChat
end if
end received audio invitation
end using terms from

When I send an audio invitation, I get absolutely no response. Any ideas?

Mike J said...

Hello, love the script, edited it to use a bonjour only account - but how do i add more names to the "set allowedBuddy to "mike@xxx"" line.

do i add more "x@x" on the same line, or repeat the line with the additional "x@x" on each line.

the mission is to have auto accept on bonjour only from multiple computers.

is there a way to accept all bonjour but not "outside" requests.

this would be much easier if apple allowed user based alerts for bonjour as they do from the buddy list.

thanks in advance.

mk2tmr2 said...

This has stopped working with Snow Leopard and the accompanying iChat AV update.

Anonymous said...

any thoughts on when this script might be fixed with Snow leopard? There is something broke in it and I miss it dearly.

Anonymous said...

I added these, seemed to work:

on received local screen sharing invitation theText from theBuddy for theChat
accept theChat
end received local screen sharing invitation
on received remote screen sharing invitation theText from theBuddy for theChat
accept theChat
end received remote screen sharing invitation

Anonymous said...

iChat 5.0 has 2 new events: share buddy's screen and share my screen. You have to run the autoaccept script for each of these, and and the above post to the script.