Thank you for your help. I’m now able to get the variable to pass through in my script that only processes one at a time. For some reason in the larger script it still won’t define my PromoCodec variable. I think you are right about all the error checks in the original script. I understand why they are there (I was originally and end user of this script/application), but you are right in that it is making it impossible for me to debug.
What I’m going to try to do is rebuild the checks one piece at a time so that I can properly debug each step. I really appreciate your help.
Here is the working script that reads an individual file and returns it’s specs using MediaInfo CLI:
set TEST to (choose file)
set tracks to the mediainfoFile(TEST)'s tracks
set info to trackInfo given type:"Video", key:"Commercial_name"
if the info = false then error "Incorrect Codec"
set PromoCodec to (trackInfo given type:"Video", key:"Commercial_name")
set PromoBitRate to (trackInfo given type:"Video", key:"Bit_rate")
set PromoDuration to (trackInfo given type:"Audio", id:2, key:"Duration")
set PromoWidth to (trackInfo given type:"Video", key:"Width")
set PromoHeight to (trackInfo given type:"Video", key:"Height")
set PromoFrameRate to (trackInfo given type:"Video", key:"Frame_rate")
set FrameRate to returnNumbersInString(PromoFrameRate)
set Frames to SAR(FrameRate, ".", "")
set theDuration to returnNumbersInString(PromoDuration)
set Duration to SAR(theDuration, ", ", ".")
set PromoSpecs to {PromoCodec, PromoBitRate, FrameRate, Duration}
--HANDLERS:
on trackInfo given type:type as text, id:|id| as text : -1, key:key as text
local key, |id|, type
global tracks
tell application "System Events"
if |id| = -1 then
set {trackdata} to the |tracks| where ¬
value of the XML attribute "type" = |type|
else
set {trackdata} to the |tracks| where ¬
value of the XML attribute "type" = |type| and ¬
value of the XML attribute "streamid" = |id|
end if
tell (a reference to XML element named key in the trackdata) to ¬
if it exists then
return its value
else
return false
end if
end tell
end trackInfo
on mediainfoFile(inputstring) -- Only call this once per script run
set theFile to quoted form of POSIX path of (inputstring)
set xmltext to do shell script "usr/local/bin/mediainfo " & ¬
theFile & " --Output=XML"
tell application "System Events"
set xml to make new XML data with properties {text:xmltext}
set mediaInfo to XML element "Mediainfo" of xml
set |file| to XML element "File" of mediaInfo
return {|tracks|:a reference to XML elements of |file|}
end tell
end mediainfoFile
on returnNumbersInString(inputstring)
set s to quoted form of inputstring
do shell script "sed s/[a-zA-Z\\']//g <<< " & s
set dx to the result
set numlist to {}
repeat with i from 1 to count of words in dx
set this_item to word i of dx
try
set this_item to this_item as number
set the end of numlist to this_item
end try
end repeat
return numlist
end returnNumbersInString
on SAR(main_text, search_text, replace_text)
set old_delims to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to search_text
considering case
set parts to every text item of main_text
end considering
set AppleScript's text item delimiters to replace_text
set newText to (parts as string)
end try
set AppleScript's text item delimiters to old_delims
return newText
end SAR
return PromoSpecs