2

I am trying to create an applescript to capture a window. The keyboard shortcut is cmd+shift+4 then space. I am not able to use this in applescript.

My code :

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

It doesnt work. The problem with the scrip it using space bar. I need to hold cmd, shift & 4 and then press space bar.

4

3 回答 3

3

尝试:

tell application "System Events"
    keystroke (ASCII character 36) using {command down}
    delay 1
    keystroke space
end tell
于 2012-12-27T11:53:15.327 回答
2

这个 Applescript 可能比使用屏幕捕获命令行的 GUI 脚本更适合您。有关更多信息,请查看屏幕截图手册页

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 & "\""
于 2012-12-28T10:55:37.897 回答
0

如果您只想达到这一点,请使用以下命令: 使用 {shift down, command down}
告诉应用程序“系统事件”键代码 21 延迟 0.1 键代码 49 end tell



于 2017-11-13T06:14:12.810 回答