Created
June 26, 2013 19:02
-
-
Save joyrexus/5870416 to your computer and use it in GitHub Desktop.
Coffee script that records and saves a quicktime audio file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env coffee | |
# | |
# usage: | |
# record.coffee -t SECS FILE | |
# record.coffee --time SECS FILE | |
# | |
# e.g., to record a 10 second audio clip: | |
# | |
# record.coffee --time 10 ~/Documents/Trials/08/audio | |
# | |
applescript = require 'applescript' | |
exec = require('child_process').exec | |
argv = require('optimist') | |
.alias('t', 'time') | |
.default('t', 5) | |
.describe('t', 'Time in seconds to record') | |
.argv | |
print = console.log | |
file = argv._[0] | |
target = if file? then file + ".mov" else __dirname + "/audio.mov" | |
move = (source, target, err_handler) -> | |
exec "mv #{source} #{target}", (err) -> err_handler err | |
record = (secs=5, file) -> | |
script = """ | |
tell application "QuickTime Player" | |
activate | |
close every window saving no | |
set audioRecording to (new audio recording) | |
tell audioRecording | |
start | |
delay #{secs} | |
stop | |
end tell | |
save | |
close every window saving no | |
end tell | |
""" | |
applescript.execString script, (err, r) -> | |
if err | |
print "error!" | |
else | |
print r if r | |
move '~/Movies/Audio*Recording.mov', file, (err) -> | |
if err | |
print err | |
else | |
print "Created #{file} with #{secs} seconds of audio!" | |
record argv.time, target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment