Quicktime Player在Mavericks系统下使用Applescript录制是否出现故障?

4

我有这样一个简单的代码:

tell application "QuickTime Player"
activate
new screen recording
document "Screen Recording" start
delay 10
document "Screen Recording" stop
end tell

这在我的10.8机器上记录了一个10秒的电影,没有任何问题。但是在10.9的mac-mini上,QT在上面的停止操作处挂起。它在带有“完成录制”消息的窗口中挂起。我不得不强制退出它,仍然是同样的情况。如果我手动执行这些步骤,它们可以正常工作。但使用AppleScript甚至使用Automator相同的步骤也会出现同样的问题。
我升级到10.9.2,但问题仍然存在。
这是已知的错误吗?有没有解决方法?
谢谢。

我已经检查了你的脚本,并发现在10.9上出现了同样的挂起问题,所以你的问题是有效的。不幸的是,我没有解决方案。 - regulus6633
感谢regulus6633在你的端上进行检查。看起来这是一个非常奇怪的 bug。 - user43823
3个回答

3

我通常使用以下方法来录制CI中的屏幕,这个方法对我总是有效:

set filePath to (path to desktop as string) & "ScreenRecordingFile.mov"

tell application "System Events" to tell process "Simulator"
 set frontmost to true
end tell

tell application "QuickTime Player"
 activate
 set newScreenRecording to new screen recording
 delay 1
 tell application "System Events"
  tell process "QuickTime Player"
   set frontmost to true
   key code 49
  end tell
 end tell
 tell newScreenRecording
  start
  delay 15
  stop
 end tell
 export document 1 in (file filePath) using settings preset "720p"
 close document 1 saving no
end tell


2

我遇到了同样的问题并发现问题不在于stop,而是在于非交互式的start,所以我尝试以伪交互方式开始录制,结果完美解决了问题。

tell application "QuickTime Player"
    activate
    new screen recording
    activate
    tell application "System Events" to tell process "QuickTime Player"
        key code 49
    end tell
    document "Screen Recording" start
    delay 10
    document "Screen Recording" stop
end tell

它仍然调用start而不是模拟点击,因为我没有找到使其工作的方法。


0

需要两个技巧:

  1. 在开始之前向QuickTime Player发送一个空格键,以避免Finishing...对话框被卡住。(感谢@outring)
  2. 我们需要模拟鼠标点击。这并不容易,我们需要通过CoreGraphics(又名Quartz)来实现。我们可以用Objective-C(需要编译),Python(通过PyObjc桥接)或Swift来编写。
  3. 不知何故,录制大约在鼠标点击后2秒开始,因此我们需要睡眠12秒以获得10秒的视频。

一个可行的脚本将如下所示:

tell application "QuickTime Player"
   activate
   new screen recording
   tell application "System Events" to tell process "QuickTime Player" to key code 49
   document "Screen Recording" start
   do shell script "python -c 'import Quartz; mouse_location = Quartz.NSEvent.mouseLocation(); [ Quartz.CGEventPost(Quartz.kCGHIDEventTap, Quartz.CGEventCreateMouseEvent(None, mouse_action, mouse_location, Quartz.kCGMouseButtonLeft)) for mouse_action in [ Quartz.kCGEventLeftMouseDown, Quartz.kCGEventLeftMouseUp ] ]'"
   delay 12
   document "Screen Recording" stop
end tell

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接