2015-11-04 43 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