使用applescript快速设置相机

时间:2015-05-01 20:14:04

标签: macos camera applescript quicktime recording

我知道这可能是一个非常简单的答案。我正在尝试设置一个Applescript应用程序,当激活时将启动quicktime,打开新的电影录制,设置摄像机和音频,开始录制,然后结束录制并在30秒后保存。

我目前有一个脚本,除了设置相机和音频源外,它正在做所有事情。关于如何使用applescript选择某个摄像机和音频源的任何提示?

谢谢!

这是现在的代码..

--Set some Variables

--Max length of recording
set maxrec to 20 --in seconds

--Ending Message
set EndMsg to "Thank you for participating in this project. Your video has been recorded."


--Begin Loop
repeat
--Get the person's name
repeat
    display dialog "What's your name?" default answer ""
    set theName to (text returned of result)
    if theName ≠ "" then exit repeat
end repeat

--Set the date
set theDate to current date
set y to text -4 thru -1 of ("0000" & (year of theDate))
set m to text -2 thru -1 of ("00" & ((month of theDate) as integer))
set d to text -2 thru -1 of ("00" & (day of theDate))
set h to text -2 thru -1 of ("00" & (hours of theDate))
set mm to text -2 thru -1 of ("00" & (minutes of theDate))
set dateStamp to (y & "-" & m & "-" & d & " " & h & mm as string)

--Create a folder for the person
tell application "Finder"
    set p to path to movies folder from user domain
    try
        make new folder at p with properties {name:"Video Clips"}
    end try
    set p to (path to movies folder from user domain as text) & "Video Clips:"
    make new folder at p with properties {name:dateStamp & " " & theName}
    set thePath to result

    --Establish the final name of the movie
    set fileName to ((thePath as text) & dateStamp & ".mov" as string)
end tell

--Open New Recording, start and stop it
tell application "QuickTime Player"
    set newMovieRecording to new movie recording
    set windowID to id of first window whose name = "Movie Recording"
    delay 2
    tell newMovieRecording
        --Set Camera to Blackmagic
        set current camera of newMovieRecording to Blackmagic of video recording devices
        start
    end tell
    set theSeconds to maxrec
    repeat theSeconds times
        display dialog theSeconds buttons {} giving up after 1 with title "REMAINING TIME"
        set theSeconds to (theSeconds - 1)
    end repeat
    tell newMovieRecording
        stop
    end tell

    --save and close the recording  
    set newMovieRecordingDoc to first document whose name = (get name of first window whose id = windowID)
    tell newMovieRecordingDoc to save in fileName
    set SavedRecordingDoc to first document whose name = (get name of first window whose id = windowID)
    tell SavedRecordingDoc to close
    quit

end tell

--Display "Thank You" Message
tell application "System Events" to set frontmost of process "Video Booth" to true
display dialog EndMsg giving up after 20 buttons {"Continue…"} ¬
    default button 1
end repeat

这是我运行时遇到的错误。

错误“QuickTime播放器出错:无法将文件”电影录制“的每个视频录制设备的Blackmagic变成类型说明符。”从文件“电影录制”的每个视频录制设备的Blackmagic到编号为-1700到说明符

2 个答案:

答案 0 :(得分:1)

使用电影录制对象的current cameracurrent microphone属性。只需用适当的设备替换第1项:

set current camera of recording to item 1 of video recording devices
set current microphone of recording to item 1 of audio recording devices

答案 1 :(得分:0)

我通过手动完成此操作

tell application "System Events" to tell process "QuickTime Player"
    #To open dialog to show available cameras
    click button 3 of window 1
    #To select our device
    click menu item "your_camera_name" of menu 1 of button 3 of window 1
end tell

这样对话框就会打开,你将从列表中选择你的相机......

取自我做的另一个答案: https://stackoverflow.com/a/45454785/3685973