Automating Mac via email. Issue with finding contact email.

Basically I want to be able to control my Mac via email. I understand the process can become quiet tedious seeing as you have to set rules up in Mail to activate applescript to start an Automator application. But, I am the type of person that relies very heavily on my Mac and my memory is horrible. Currently I am trying to make a script that when I receive and email with Mac FindContact as subject and then the body of the email is the person I am trying to find. For this example we will use my name “Aaron”. I offset the name I am looking for with %& as this makes it easier to find later on in the workflow.
The workflow I have in place is as follows:

  1. Hide All Applications
  2. Search Entourage Items (Raw Query “Mac FindContact”)
  3. Get Text from Entourage Mail Messages
  4. Copy to Clipboard
  5. Run AppleScript
on run {input, parameters}
	
	set MasTxt to (the clipboard as text)
	set FindName to text ((offset of "%&" in MasTxt) + 2) thru -1 of MasTxt
	set input to FindName
	
	return input
end run
  1. Copy to Clipboard

Now I have played around with:

set thePeople to every person whose name = "Aaron"
set infoperson to properties of (item 1 of thePeople)

In a separate applescript to figure somethings out. And that retrieves the contact information, granted a lot of extra junk comes with that but time being I can suffice. The problem comes when I try to set anything to infoperson, I get a HUGE error. (When quoted it below it removed some of the error however I doubt it was important just a lot of repeating characters)

Any thoughts? Am I going about this the wrong way? Is there an easier way? What can I do? Thanks in advance!

I am new to the board and scripting, sorry I won’t be able to help much. But it occurs to me you might just want to remotely control your Mac using software that allows for this. Remote Desktop on the mac and VNC. Details how to set up are on this web page. Then you could just see your remote mac’s desktop on whatever other computer you might be at.

http://www.macminicolo.net/Mac_VNC_tutor.html

I appreciate the link CamM, however I don’t tend to carry around a laptop with me when I go places. If that were the case I would be all over VNC. What I do carry however it a Samsung Finesse. The only thing that piece of equipment gives me is the ability to check and send email and txt. I know the email address of my phone as well. So with automator I could essentially txt my phone by sending my XXX.XXX.XXXX@sms.thumbcellular.com an email.

I’m getting somewhere, or, I started over and am at the same place I was earlier with a slightly different workflow.

  1. Search Entourage Items ([SMS from mobile subscriber]) *note1
  2. Get Text from Entourage
  3. Copy to Clipboard *note2
  4. Run AppleScript
on run {input, parameters}
	
	set mailMSG to (the clipboard as text)
	set bodyMSG to text ((offset of "~!@" in mailMSG) + 3) thru -1 of mailMSG
	set thePerson to text ((offset of "*&^" in bodyMSG) + 3) thru -2 of bodyMSG
	set input to thePerson
	
	
	return input
end run
  1. Get Specified Address Book Items *note3
  2. Get Contact Information *note4
  3. Create New Entourage Mail Message (email:my cell subject:contact found body:)
  4. Send Outgoing Entourage Mail Message

*Note 1: I decided instead of sending an email from my phone to send a txt
*Note 2: For some reason I need to copy it to clipboard in order to pass it to Run AppleScript. I tried set mailMSG to (input) and it shows up in the scripts however I end up receiving an error later on.
*Note 3: Now somewhere between note 3 and 4 is where my issue is coming from. My applescript will find the contact I am looking for. When it passes it to the next step the next step shows the persons name in the results panel of that step. However, what it does not seem to do is actually get that contact. None of the contact information will be passed to the next step.

If you want to see my exact workflow follow this link: http://dl.dropbox.com/u/1216523/find contact.zip

I’m so close. Push me in the right direction guys.

Model: Mac MINI
AppleScript: 2.2.1
Browser: Safari 531.21.10
Operating System: Mac OS X (10.5)

Hi,

on macosxhints there is an article which describes to control your mac via email. It’s quite old but it should work also on the current OS
Use AppleScript and Mail for remote control and file access - Mac OS X Hints

Thank you very much for this. I plan on utilizing this instead of my automator workflow. However, my main problem now is still how to i ask for a particular contact and get that info back?

Model: Mac MINI
AppleScript: 2.2.1
Browser: Safari 531.21.10
Operating System: Mac OS X (10.5)

You can ask Address Book for the information


set thePerson to "John Doe"
try
	tell application "Address Book"
		set foundPerson to (first person whose name is thePerson)
		tell address 1 of foundPerson
			set theCity to city
			set theStreet to street
			set theZIP to zip
		end tell
	end tell
	display dialog "person '" & thePerson & "':" & return & theStreet & return & theZIP & space & theCity
on error
	display dialog "person '" & thePerson & "' not found"
end try

StefanK, I love you brotha!:lol:

Don’t know if this is helpful…it doesn’t use Automator, and I included parts from Stefan and other sources as well. It is completely AS, I use Mail instead of Entourage, but I am sure it would work their as well. I just have a rule look for the incoming email with {Name Search} in the body of the SMS (my phone sends a text with the subject and body being exactly the same) that is from my cellphone (sender = xxxxxxxxxx@text.com) and runs the AS to parse out the Person’s name to search Address Book for. It then sends an email/sms back to the cell phone that it received the request for. I am sure the code could be cleaned up slightly, I am fairly new to scripting, but it works.

Cheers,
Mark


using terms from application "Mail"
	on perform mail action with messages actionMail for rule actionRule
		tell application "Mail"
			repeat with i from 1 to count of actionMail
				
				set thisMail to item i of actionMail
				set mailMsg to the content of thisMail
				set thePerson to text ((offset of "{Name Search}" in mailMsg) + 13) thru -2 of mailMsg
				
				set theSender to the sender of thisMail
				
				try
					tell application "Address Book"
						set foundPerson to (first person whose name is thePerson)
						tell address 1 of foundPerson
							set theCity to city
							set theStreet to street
							set theState to state
							set theZip to zip
						end tell
						
						set mobileNumber to (value of phones of foundPerson whose label contains "mobile")
						
						set homeNumber to (value of phones of foundPerson whose label contains "home")
						
						set personData to thePerson & return & theStreet & return & theCity & space & theState & space & space & theZip & return & "Mobile: " & mobileNumber & return & "Home: " & homeNumber
						my sendThis(personData, theSender)
					end tell
					
				on error
					set personData to thePerson & " was not found."
					my sendThis(personData, theSender)
					
				end try
			end repeat
		end tell
		
		quit application "Address Book"
		
	end perform mail action with messages
end using terms from

to sendThis(personData, theSender)
	try
		
		tell application "Mail"
			set newMsg to make new outgoing message with properties {subject:"Person Query Reply", content:personData & return & return}
			
			tell newMsg
				set visible to true
				set sender to theSender
				make new to recipient at end of to recipients with properties {address:theSender}
			send
                       end tell
		end tell
	end try
	
end sendThis


Model: iMac
AppleScript: 2.1.1 (ASE 2.3)
Browser: Safari 531.21.10
Operating System: Mac OS X (10.6)