Skip to content

Instantly share code, notes, and snippets.

@iluvcapra
Created January 31, 2009 09:22
Show Gist options
  • Save iluvcapra/55493 to your computer and use it in GitHub Desktop.
Save iluvcapra/55493 to your computer and use it in GitHub Desktop.
Generate an AppleScript from a CMX-format Edit Decision List
#!/usr/bin/ruby
#read EDL for start times
class Event
attr_accessor :start
attr_accessor :finish
attr_accessor :clip_name
def start
@start.without_punctuation
end
def finish
@finish.without_punctuation
end
def clip_name
@clip_name ? @clip_name : "NO CLIP NAME IN EDL"
end
end
class String
def without_punctuation
self.delete("+:.")
end
end
events = []
action = ARGV.shift
ARGV.each do |file|
File.open(file,"r") do |fd|
e = nil
fd.each_line("\r\n") do |line|
if line[0..2].match(/\d\d\d/) then
edit_chans = line.slice(14..18)
if edit_chans && edit_chans.include?("V") then
events << e if e
e = Event.new
e.start = line.slice(53..63)
e.finish = line.slice(65..75)
end #if
elsif line[0].chr == "*" && e then
md = line.match(/^\* FROM CLIP NAME: (.*)$/)
e.clip_name = md[1].strip.sub(/\-/,"/") if md
events << e
e = nil
end
end #each_line
end #File.open
end #ARGV.each
system "osascript" , "-e" , <<-ACTIVATE
tell application "Pro Tools HD"
activate
end tell
ACTIVATE
events.each do |event|
script_command = case action
when 'paste'
<<-ASCRIPT
tell application "System Events"
keystroke "=#{event.start}"
delay .1
keystroke (ASCII Character 3) -- enter key, to locate
delay .1
keystroke "v" using command down
delay .1
end tell
ASCRIPT
when 'region'
<<-BSCRIPT
tell application "System Events"
keystroke "/#{event.start}/#{event.finish}"
delay .1
keystroke (ASCII Character 3) -- enter key, to locate
delay .1
keystroke "g" using (command down , option down)
delay .1
keystroke "r" using (command down , shift down)
delay .1
keystroke "#{event.clip_name}"
delay .1
keystroke return
delay .1
end tell
BSCRIPT
end
puts script_command
system "osascript" , "-e" , script_command
end #each
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment