Thanks so much!
This is really close to what I need. I modified it a little by adding the path to the file I want to always save in and took away the dialog boxes and it almost does it. It constantly updates the .xml file with the annotations from the current movie, which is great. I don’t actually need to make sure I’m not processing a movie that has already been processed, which isn’t hard to take out. What I do need to do that I can’t figure out is to trigger another application whenever a new movie is opened (regardless of whether it has been opened in the past or not).
This script works great except for the above mentioned things:
global processedFullNames
on run
set processedFullNames to {}
end run
on idle
tell application "QuickTime Player 7"
if annotation "full name" of document 1 exists then
set fullAnotName to full text of annotation "full name" of document 1
else
set fullAnotName to " "
end if
end tell
--if fullAnotName is not in processedFullNames then
--set end of processedFullNames to fullAnotName
saveAnnot()
--end if
--display dialog processedFullNames as string
return 1
end idle
(* ===== SAVE ANNOTATION ===== *)
on saveAnnot()
tell application "QuickTime Player 7"
-- FULL NAME
if annotation "full name" of document 1 exists then
set annot_fullname to full text of annotation "full name" of document 1
else
set annot_fullname to " "
end if
if first character of annot_fullname is "*" then set annot_fullname to " "
-- ARTIST
if annotation "artist" of document 1 exists then
set annot_artist to full text of annotation "artist" of document 1
else
set annot_artist to " "
end if
if first character of annot_artist is "*" then set annot_artist to " "
end tell
-- WRITE DATA TO FILE
-- get data
set myData to "<?xml version=\"1.0\"?>" & return & return & "<fmaStream>" & return & tab & "<data>" & return & tab & tab & "<title>" & annot_fullname & "</title>" & return & tab & tab & "<artist>" & annot_artist & "</artist>" & return & tab & "</data>" & return & "</fmaStream>"
set myData to myData as string
-- make new file
set myFile to "/users/brucejames/desktop/testxml2.xml" as Unicode text
--set myFile to POSIX path of (choose file name with prompt "Where do you want to save the XML?")
--makeFile(myFile, 1)
-- write string
set OA to open for access alias (my HSFWithPOSIX(myFile)) with write permission
write myData to OA starting at 0
close access OA
--display dialog "Annotations Saved" giving up after 1
end saveAnnot
(* ===== HANDLERS ===== *)
on makeFile(filename, sizeInBytes)
try
do shell script "mkfile " & sizeInBytes & "b " & my stringForTerminal(filename)
return true
on error
return false
end try
end makeFile
on stringForTerminal(filename)
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set allItems to every text item of filename
set AppleScript's text item delimiters to "\\ "
set newPath to allItems as text
set AppleScript's text item delimiters to tid
return newPath
end stringForTerminal
on HSFWithPOSIX(filename)
set myAlias to (POSIX file filename)
set myAlias to myAlias as string
return myAlias
end HSFWithPOSIX
This is the first bit where I tried to come up with a way to check for matching between the current movie and the one played before:
global processedFullNames
on run
set processedFullNames to {}
end run
on idle
tell application "QuickTime Player 7"
if annotation "full name" of document 1 exists then
set fullAnotName to full text of annotation "full name" of document 1
else
set fullAnotName to " "
end if
end tell
delay 3
tell application "QuickTime Player 7"
if document 1 exists then
set annot_fullname to full text of annotation "full name" of document 1
else
set annot_fullname to " "
end if
if (annot_fullname = fullAnotName) is false then display dialog "it is false" --this would be if a new movie had been opened and is where I would trigger the upload application
--if fullAnotName is not in processedFullNames then
--set end of processedFullNames to fullAnotName
saveAnnot()
end tell
--display dialog processedFullNames as string
return 1
end idle
But when I run this bit in the full script, I get the error, “Can’t continue saveAnnot.”
Any further thoughts?
Thanks again for your help on this.
In case it’s useful, here’s the full context of what I’m doing:
I use iCal to trigger Automator applications that get a series of Quicktime movies and play them in order on a plasma screen (in a university film department). There is typically one of these applications triggered by iCal every hour all day. These are films made by students in our department.
We also capture the plasma screen (using Wirecast software) and send it as a webcast to the front page of our web site. What I’m trying to enable is live updating of the title and artist to the web site as the movies play. I used to do this all in Automator, but we kept getting all kinds of errors on various parts of the workflows. This was in 10.6. Since then, I’ve downgraded to 10.5 and still get the errors, so I thought I’d try just running the Quicktime playlists in Automator, since that’s very simple, and then using Applescript to get the names, save them in an xml, and trigger another simple Automator application to upload that xml (using Fetch) whenever a new movie is opened.
Thanks,