Applescript捕获窗口

时间:2012-12-27 11:14:05

标签: applescript

我正在尝试创建一个抓取窗口的AppleScript。键盘快捷键是cmd + shift + 4然后是空格。我无法在AppleScript中使用它。

我的代码:

tell application "system events"
keystroke "21, 49" using {command down, shift down}
end tell

它不起作用。使用空格键的脚本问题。我需要按住 cmd shift & 4 然后按 space 吧。

3 个答案:

答案 0 :(得分:3)

尝试:

tell application "System Events"
    keystroke (ASCII character 36) using {command down}
    delay 1
    keystroke space
end tell

答案 1 :(得分:1)

此Applescript可能对您更有效,而不是使用GUI脚本 它使用屏幕捕获命令行。有关详细信息,请查看screencapture Man page

set fileName to do shell script "date \"+Screen Shot  %Y-%m-%d at %H.%M.%S.png\""
tell application "System Events" to set thePath to POSIX path of desktop folder
do shell script "screencapture  -W " & "\"" & thePath & "/" & fileName & "\""

答案 2 :(得分:0)

If all you want is to get to that point then use this:
tell application "System Events"
key code 21 using {shift down, command down}
delay 0.1
key code 49
end tell