有没有办法暂停录音并使用 quicktime 和 applescript 恢复录音?
Is there a way to pause audio recording and resume with quicktime and applescript?
我在 AppleScript 中尝试过:
tell application "QuickTime Player"
activate
set doku to new audio recording
start doku
delay 4
pause doku
end tell
虽然它启动 QuickTime 播放器并开始录制它不会暂停,但有没有办法使用 AppleScript 和 QuickTime 播放器暂停→播放→暂停等来录制音频?
好的,我对此进行了深入研究并提出了以下脚本。如果录音 window 已打开,此脚本将在录音暂停时开始或恢复录音,否则暂停录音。这使用 python 模拟选项键按下(按住选项键将 'stop' 按钮变成 'pause' 按钮),因此您可能需要安装 python 的 Objective-C 包。有关详细信息,请参阅 : 我刚刚发现 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 调用)。我不确定您的工作流程是什么样的,我不想通过发出不方便的警报来破坏它。
我在 AppleScript 中尝试过:
tell application "QuickTime Player"
activate
set doku to new audio recording
start doku
delay 4
pause doku
end tell
虽然它启动 QuickTime 播放器并开始录制它不会暂停,但有没有办法使用 AppleScript 和 QuickTime 播放器暂停→播放→暂停等来录制音频?
好的,我对此进行了深入研究并提出了以下脚本。如果录音 window 已打开,此脚本将在录音暂停时开始或恢复录音,否则暂停录音。这使用 python 模拟选项键按下(按住选项键将 'stop' 按钮变成 'pause' 按钮),因此您可能需要安装 python 的 Objective-C 包。有关详细信息,请参阅 我刚刚发现 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 调用)。我不确定您的工作流程是什么样的,我不想通过发出不方便的警报来破坏它。