在小牛队打破苹果的Quicktime播放器录音?

时间:2014-03-27 00:45:30

标签: macos applescript quicktime

我有这个简单的代码:

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在上面的停止动作中挂起。 它挂在窗口,显示消息“Finishing Recording”。 我必须强行戒掉它,但仍然是一样的。如果我手动执行这些步骤,它们会起作用。但是使用AppleScript甚至与Automator相同的步骤都有同样的问题。

我升级到了10.9.2,但问题仍然存在。

这是一个已知的错误吗?有关解决方案的任何建议吗?

感谢。

3 个答案:

答案 0 :(得分: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




答案 1 :(得分: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而不是模拟点击,因为我还没有找到让它运行的方法。

答案 2 :(得分:0)

需要两个技巧:

  1. 在开始之前向QuickTime Player发送空格键,以避免卡住Finishing...对话框。 (信用到@outring)
  2. 我们需要模拟鼠标点击。这并不容易,我们需要通过CoreGraphics(又名Quartz)来实现。我们可以在Objective-C(需要编译),Python(通过PyObjc桥)或Swift中编写。
  3. 鼠标点击后大约2秒左右开始录音,所以我们需要在12秒钟内观看10秒钟的视频。
  4. 工作脚本如下所示:

    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