有没有办法暂停录音并使用快速时间和苹果脚本恢复?



我在AppleScript中尝试过这个:

tell application "QuickTime Player"
activate
set doku to new audio recording
start doku
delay 4
pause doku
end tell

当它启动QuickTime播放器并开始录制时,它不会暂停,有没有办法暂停→播放→暂停等AppleScript和QuickTime播放器录制音频?

好的,我对此进行了一些深入研究,并提出了以下脚本。如果"音频录制"窗口已打开,则此脚本将在录制暂停时开始或恢复录制,如果未暂停,则暂停录制。这使用 python 来模拟选项键按下(按住选项键会将"停止"按钮变成"暂停"按钮(,因此您可能需要安装 python 的 Objective-C 包。有关详细信息,请参阅此StackOverflow答案:我刚刚发现默认情况下PyObjc 2.5安装在OSX上,这对于此目的应该绰绰有余。

tell application "QuickTime Player" to activate
tell application "System Events"
tell process "QuickTime Player"
tell window "Audio Recording"
set actionButton to first button whose description is "stop recording" or description is "start recording" or description is "resume recording"
if description of actionButton is in {"start recording", "resume recording"} then
-- start/resume audio recording
click actionButton
else if description of actionButton is "stop recording" then
-- pause audio recording
my controlKeyEvent(true)
click actionButton
my controlKeyEvent(false)
end if
end tell
end tell
end tell
on controlKeyEvent(isKeyDown)
if isKeyDown then
set boolVal to "True"
else
set boolVal to "False"
end if
do shell script "
/usr/bin/python <<END
from Quartz.CoreGraphics import CGEventCreateKeyboardEvent
from Quartz.CoreGraphics import CGEventCreate
from Quartz.CoreGraphics import CGEventPost
from Quartz.CoreGraphics import kCGHIDEventTap
import time
def keyEvent(keyCode, isKeyDown):
theEvent = CGEventCreateKeyboardEvent(None, keyCode, isKeyDown)
CGEventPost(kCGHIDEventTap, theEvent)
keyEvent(58," & boolVal & ");
END"
end controlKeyEvent

现在,Quicktime Player 需要位于前台才能捕获按键事件,否则暂停将不起作用。我想我可以调整它,以便按键事件直接进入播放器应用程序,但我必须研究它。此外,我没有以任何方式编写代码来停止录制(尽管这很容易:只需单击按钮而无需controlKeyEvent 调用(。我不确定您的工作流程是什么样的,我不想通过抛出不方便的警报来破坏它。

相关内容

  • 没有找到相关文章

最新更新