2015-11-04 70 views
0

对于我的学习,我使用很多screencapture功能作为终端命令。最近我开始使用AppleScript来自动化一些屏幕截图。但现在我想推进一点。AppleScript提示点击用户

是否有可能使用诸如“显示对话框”之类的命令,而是查询2次点击,其中坐标将被分配给screencapture命令,以便拍摄屏幕图片?

我在想是这样的:

set click1 to "0,0" 
set click2 to "0,0" 
display dialog "Click where the screen area to grab begins" & click1 
display dialog "Click where the screen area to grab begins" & click2 

do shell script "screencapture -R click1,click2 /Users/user/Desktop/name_of_the_file.png" 

回答

0

的AppleScript没有捕捉鼠标点击,甚至获得位置的机制。您可以使用对框架的调用来获取鼠标位置。 但是,你将不得不求助于可可应用解决方案来捕获屏幕点击。

一个想法是,你可以使用一个applescript流程,让你放置第一个鼠标位置2秒钟,然后它可以哔哔地告诉你它已经捕获它,然后你有两秒多的时间把指针放在在捕获它之前的第二个位置。 类似这样的:

use framework "Foundation" 
use scripting additions 

display dialog "Place your mouse pointer in the first position within 2 seconds, then after the beep, place it in the second position within 2 seconds." 
delay 2 
set theList to current application's NSEvent's mouseLocation() 
set xCoord1 to theList's x 
set yCoord1 to theList's y 
beep 
delay 2 
set theList to current application's NSEvent's mouseLocation() 
set xCoord2 to theList's x 
set yCoord2 to theList's y 
beep 

display dialog (((xCoord1 as string) & ", " & yCoord1 as string) & return & xCoord2 as string) & ", " & yCoord2 as string