applescript - 有没有办法用 quicktime 和 applescript 暂停录音和恢复?
问题描述
我在 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 需要在前台捕捉按键事件,否则暂停将不起作用。我想我可以对其进行调整,以便按键事件直接进入 Player 应用程序,但我必须对其进行研究。此外,我没有以任何方式编写代码来停止录制(尽管这很容易:只需单击没有controlKeyEvent 调用的按钮)。我不确定你的工作流程是什么样的,我不想通过发出不方便的警报来破坏它。
推荐阅读
- node.js - 如何在 Node js 中构建电子邮件功能?
- php - 调用未定义的方法 App\UserShiftPattern::userWorkScheduleList()
- python - 数据框条形图与 plt.plot 的 x 轴不一致
- javascript - 403 响应代码 - 使用 Cowin setu API 时请求被阻止
- beautifulsoup - 为什么 VScode ChromeDriver 不显示我试图打开的网站 url?
- kubernetes - 无法使用自定义插件运行 Traefik:“命令 traefik 错误:无法检查插件 XXX 的存档完整性:插件完整性检查失败”
- html - 为什么
标签或任何其他标签没有相互堆叠?
- button - 使用绑定隐藏非选定 cellView 中的按钮
- arduino - Arduino led 矩阵 max7219 MCU 板点阵
- c# - .editorconfig 用于测试项目/类