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

Send SMS to Messages and run commands with AppleScript Apps
It is possible to send an SMS command to your Mac using an AppleScript. I've made one which takes a picture when I send the command /photo to iMessages on my Mac.

The script is very simple; it must be set up Messages' Alerts preferences. Choose Event > Message Received, then check Run an Apple Script. This will check each message you get for the command; in this case, /photo.

The script will turn the volume all the way down (and up again) before taking a picture with PhotoBooth so it does not make any noise.

Then you can make a symbolic link from the PhotoBooth folder to your Dropbox so you can check the photos from your mobile device.

Here's the script:
using terms from application "Messages"
	on message received theMessage from theBuddy for theChat
		
		if (theMessage begins with "/") then
			
			if theMessage begins with "Photo" then
				beep 3
			else
				set volume 0
				
				tell application "Photo Booth"
					
					activate
					
				end tell
				
				tell application "System Events"
					
					tell process "Photo Booth"
						
						delay 3
						tell application "Finder"
							set visible of process "Photo Booth" to false
						end tell
						tell menu bar 1
							
							tell menu bar item "File"
								
								tell menu "File"
									
									click menu item "Take Photo"
									
								end tell
								
							end tell
							
						end tell
						
					end tell
				end tell
				delay 5
				tell application "Photo Booth"
					quit
				end tell
				set volume 3
			end if
			
		end if
		
	end message received
	
end using terms from

[kirkmc adds: Note that this only works with iMessages (I tried for a while to get it to work with regular chats, and it wouldn't). It's worth noting that the ability to send a text message and set off a script is something very useful, and I can imagine plenty of scripters figuring out other types of remote commands they can send to their Macs. Feel free to submit them as hints.]
    •    
  • Currently 3.00 / 5
  You rated: 4 / 5 (6 votes cast)
 
[9,405 views]  

Send SMS to Messages and run commands with AppleScript | 6 comments | Create New Account
Click here to return to the 'Send SMS to Messages and run commands with AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Send SMS to Messages and run commands with AppleScript
Authored by: Jwink3101 on Oct 16, '12 07:48:22AM

This title is misleading. You do not send SMS to the messages app on Mountain Lion. Only iMessages. So the message must come from an iOS device (or another mac). Unless I am missing something



[ Reply to This | # ]
Send SMS to Messages and run commands with AppleScript
Authored by: ss3_gokoux on Oct 16, '12 08:36:51AM
imagesnap, covered on this site before, is a command line utility for silently taking iSight photos instead of the Photo Booth chicanery in the author’s script:

All of the Photo Booth code blocks could be replaced with something along the lines of…
do shell script "/path/to/imagesnap ~/Dropbox/Photos/output.jpg"

[ Reply to This | # ]
Send SMS to Messages and run commands with AppleScript
Authored by: mark hunte on Oct 16, '12 11:20:40AM
@kirkmc,
It may be worth combining my old hint http://hints.macworld.com/article.php?story=20120218043753895 example of this when iMessages was beta and this. Although I think the only change is the App name!!.
---
mh
Edited on Oct 16, '12 11:21:44AM by mark hunte


[ Reply to This | # ]
Significant security implications with this script
Authored by: bonobob on Oct 24, '12 01:57:48PM

The security implications of allowing iMessage messages to control ones computer should be noted and carefully considered before implementing something like this.



[ Reply to This | # ]
Send SMS to Messages and run commands with AppleScript
Authored by: dhaskew on Nov 01, '12 08:15:44AM

What happens if your computer is sleeping? When it wakes up it will run all the commands once iMessage has a chance to sync? Could have unexpected consequences.



[ Reply to This | # ]
Send SMS to Messages and run commands with AppleScript
Authored by: ~Coxy on Nov 01, '12 05:59:41PM

This hint is a pretty good idea (beats the heck out of SSHing back into the computer on a phone keyboard), but what is the best way to send messages to the Mac?

Is it possible to use iMessage to send a message to yourself that the Mac will get and act upon?

And then in the script, is it possible to check the name of the sender to make sure that only messages from your account are used to issue commands?



[ Reply to This | # ]