苹果脚本- Send SMS to Messages and run commands with AppleScript

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.]
    •     
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值