The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   Applications (http://hintsforums.macworld.com/forumdisplay.php?f=5)
-   -   Movie Properties Info Delete Script? (http://hintsforums.macworld.com/showthread.php?t=33176)

schneb 01-10-2005 02:25 PM

Movie Properties Info Delete Script?
 
I have a bunch of MIDI files that I am using in iTunes. Unfortunately, all the song titles are either "untitled" or reference numbers. All of the file names are the correct title. I have noticed that if I delete the Quicktime movie properties, that the filename will drop in by default and will display properly in iTunes. So, here is what I need.

I need a batch script that will allow me to strip the information in the Quicktime Movie Properties. I could probably do this later with Automator, but would like to do it now if possible.

Thanks all!

cwtnospam 01-10-2005 02:35 PM

Have you tried doing an Applescript? The Finder is scriptable, so you might be able to have the script editor record the script while you do a file. Then you apply the script to a folder, using "enable folder actions" so that you can drop the rest of the files into the folder and run the script on them automaitically.
Applescript can be a little intimidating to start, but it is good to learn for future use. I'm not great at it, but this seems like a nice project that wouldn't be too difficult.

schneb 01-10-2005 04:15 PM

Yeah, I wish I knew how to AppleScript, but right now I have to get my head around ActionScript, and programming is very difficult for me.

cwtnospam 01-10-2005 04:21 PM

If you want to send me a file, I'll give it a try. Make it a small one, I don't want to post my real email on the web, so I'm using my throwaway account:
cwtdirect@hotmail.com
Only send one, I'll just duplicate it to try the script.
;)

schneb 01-10-2005 06:29 PM

Done... it's a teeny MIDI file. Thanks!

cwtnospam 01-10-2005 09:10 PM

Got it, but now I'm stuck! How do you delete the Quicktime movie properties? I can't script it unless I know how to do it!

cwtnospam 01-10-2005 10:45 PM

Oops! Needed to delete them in Quicktime Pro. Now I know what needs to be done. I just need to figure out how to script it. Funny, Script Editor records a script and then won't run what it recorded!

schneb 01-11-2005 11:34 AM

I think stuff like that is what frustrated me about ScriptEditor. Hence I went on to other things. I am hoping Automator will change my life.

cwtnospam 01-11-2005 12:11 PM

I've managed to get it to delete the properties. Now I'm trying to get it to save the file. You'd think that would be the easy part!

schneb 01-11-2005 06:43 PM

A guy at Apple discussions showed me one at the Apple site. I ran it and it worked, but it would not save the file. The change did not "take". Here is the code if it helps at all...

Code:

-- the list of creator types which will be processed
property type_list : {"MooV"}
property extension_list : {"mid"}
property delete_existing : true
property protect_name : true

global new_annotations_list

repeat
        display dialog "Clear All Annotations Droplet

A droplet for setting the annotations of QuickTime Movie files." buttons {"Set Prefs", "Done"} default button 2
        if the button returned of the result is "Done" then exit repeat
        display dialog "Retain the existing full name of the movie?" buttons {"No", "Yes"} default button 2
        if the button returned of the result is "Yes" then
                set protect_name to true
        else
                set protect_name to false
        end if
end repeat

-- This droplet processes both files or folders of files dropped onto the applet
on open these_items
        -- this routine uses the gestaltVersion_info() sub-routine
        copy my gestaltVersion_info("qtim", 8) to {QT_version, QT_string}
        if the QT_version is less than "0502" then
                display dialog "This script requires QuickTime 5.0.2 or higher." & ¬
                        return & return & "The currently installed version is: " & ¬
                        QT_string buttons {"Cancel"} default button 1
        end if
        repeat with i from 1 to the count of these_items
                set this_item to (item i of these_items)
                set the item_info to info for this_item
                if folder of the item_info is true then
                        process_folder(this_item)
                else if (alias of the item_info is false) and ¬
                        ((the file type of the item_info is in the type_list) or ¬
                                the name extension of the item_info is in the extension_list) then
                        process_item(this_item)
                end if
        end repeat
end open

-- this sub-routine processes folders
on process_folder(this_folder)
        set these_items to list folder this_folder without invisibles
        repeat with i from 1 to the count of these_items
                set this_item to alias ((this_folder as text) & (item i of these_items))
                set the item_info to info for this_item
                if folder of the item_info is true then
                        process_folder(this_item)
                else if (alias of the item_info is false) and ¬
                        ((the file type of the item_info is in the type_list) or ¬
                                the name extension of the item_info is in the extension_list) then
                        process_item(this_item)
                end if
        end repeat
end process_folder

-- this sub-routine processes files
on process_item(this_item)
        -- NOTE that the variable this_item is a file reference in alias format
        -- FILE PROCESSING STATEMENTS GOES HERE
        tell application "QuickTime Player"
                launch -- bypasses promo movie
                activate
                my toggle_suppress(true)
               
                stop every movie
                close every movie saving no
               
                try
                        open this_item
                        if saveable of movie 1 is false then
                                error "This movie has previously been set so that it cannot be copied, edited, or saved."
                        end if
                        -- remove any existing annotations
                        try
                                if protect_name is true then
                                        set the full text of (every annotation whose name is not "Full Name") to ""
                                else
                                        set the full text of every annotation to ""
                                end if
                        end try
                        close movie 1 saving yes
                on error error_message
                        try
                                beep
                                display dialog error_message buttons {"Cancel", "Continue"} default button 2 with icon 1
                                close movie 1 saving no
                        on error
                                my toggle_suppress(false)
                                error number -128
                        end try
                end try
                my toggle_suppress(false)
        end tell
end process_item

on toggle_suppress(status_flag)
        tell application "QuickTime Player"
                set ignore auto play to the status_flag
                set ignore auto present to the status_flag
        end tell
end toggle_suppress

on gestaltVersion_info(gestalt_code, string_length)
        try
                tell application "Finder" to ¬
                        copy my NumToHex((system attribute gestalt_code), ¬
                                string_length) to {a, b, c, d}
                set the numeric_version to {a, b, c, d} as string
                if a is "0" then set a to ""
                set the version_string to (a & b & "." & c & "." & d) as string
                return {numeric_version, version_string}
        on error
                return {"", "unknown"}
        end try
end gestaltVersion_info

on NumToHex(hexData, stringLength)
        set hexString to {}
        repeat with i from stringLength to 1 by -1
                set hexString to ((hexData mod 16) as string) & hexString
                set hexData to hexData div 16
        end repeat
        return (hexString as string)
end NumToHex


cwtnospam 01-11-2005 07:48 PM

Seems kind of complicated. I'm trying to set up a folder action where the script will have Quicktime Pro open the file, remove the movie properties and then save the file. This is what I have so far:

set annot1 to "Full Name"
set annot2 to "Copyright"
tell application "Finder" to display dialog "'" & aItem & "'" buttons {"Yes", "No"} default button 2 with icon 1
tell application "QuickTime Player" to open aItem

tell application "Finder" to display dialog aItem & " has been opened. " buttons {"Yes", "No"} default button 2 with icon 1
tell application "QuickTime Player"
delete annotation annot1
delete annotation annot2
end tell
tell application "Finder" to display dialog aItem & " has been cleared. " buttons {"Yes", "No"} default button 2 with icon 1
--tell application "QuickTime Player"
-- set nme to name of annotation "Music Track"
--end tell
--tell application "Finder" to display dialog nme buttons {"Yes", "No"} default button 2 with icon 1
set plce to folder2 & aItem
tell application "QuickTime Player"
save aItem in folder2 as movie
end tell
tell application "Finder" to display dialog aItem & " has been saved. " buttons {"Yes", "No"} default button 2 with icon 1


I've got the display dialogs in there to help me debug. I get to save, which I've tried in lots of ways, and it fails. Still working on it though!

cwtnospam 01-11-2005 07:58 PM

Doh! You aren't going to believe this. I just upgraded to the latest iTunes (4.7.1) and added your file in. The song name came up as: Player Piano Roll # 52923A
Apparently, Apple was one step ahead of us. A script is no longer required!

bramley 01-12-2005 05:23 AM

Although cwtnospam has discovered that the problem appears to have been resolved by upgrading iTunes, I have on occasion run into similar problems with MP3, AAC etc i.e where the track name has a different name to that of the file name. (In fact if you look closely at any tracks you've put on your system with the "Get CD Track Names" option, you will see file names do differ from track names as a result of the process.)

So I did the following AS to sort out name conflicts. To use, select the track in iTunes, and run the script. The track name will be edited to be the file name minus the extension.

Don't know if it works for MIDI files, but I don't see why it shouldn't.

Code:

tell application "iTunes"
        activate
        copy selection to tracksToRename
        repeat with aTrack in tracksToRename
                set currentAlias to location of aTrack
                tell application "Finder" to set fileName to name of currentAlias
                set name of aTrack to my removeExtension(fileName)
        end repeat
end tell

on removeExtension(theName)
        set tempStore to AppleScript's text item delimiters
        set AppleScript's text item delimiters to "."
        set bitsOfName to items 1 thru -2 of (text items of theName)
        set outputName to bitsOfName as string
        set AppleScript's text item delimiters to tempStore
        return outputName
end removeExtension


schneb 01-12-2005 05:39 PM

Bramley,

Cwtnospam was a bit confused about the new version of iTunes, it will not convert or display the MIDI files correctly. But your script, on the other hand, did the trick! Many thanks for it and a big thank you to cwtnospam who tried to make the QT script work.

Thanks again!

cwtnospam 01-12-2005 07:56 PM

You're welcome. I'm still trying to get Quicktime to do it by deleting the movie properties. For some reason, I can't get it to open a file from a script!
For example:

tell application "QuickTime Player"
activate
open "Macintosh HD:Users:shared:anymoviename.mov"

will fail! I'm glad you don't need it, bu now I don't want to let it win. :o

cwtnospam 01-13-2005 08:40 PM

A little late, but I got it to work! Just in case you're interested, the script is below. It works using a folder action and requires two folders. One to drop the files into and another folder at the same level and named the same, but with the number 2 at the end. After running the script, just add files from folder2 into iTunes.


on adding folder items to this_folder after receiving added_items
try
tell application "Finder"
set the folder_name to the name of this_folder
set l to the length of folder_name
set cpya to folder of this_folder
set cpy to ((cpya as string) & folder_name) as string
set ai to length of cpy
set annot1 to "Full Name"
set annot2 to "Copyright"
end tell
repeat with aItem in added_items
set lai to aItem as string
set la to length of lai
set adj to ai + 2
set fl to characters adj through la of lai as string
set fnm to cpy & "2:" & fl as string
tell application "QuickTime Player"
open aItem
delete annotation annot1 in movie 1
delete annotation annot2 in movie 1
save movie 1 in fnm
close movie 1 saving no
end tell
end repeat
end try
end adding folder items to

schneb 01-13-2005 09:34 PM

I had never done a folder action before, so this took some figuring out. Once I got it going, it sorta worked, then crashed QT.

cwtnospam 01-13-2005 09:56 PM

Did it convert some files and then crash? I only tested it on a few duplicates of that one file.

schneb 01-13-2005 10:12 PM

Yeah, it converted a couple then crashed. I think I might know why. Some of the files have two data entries and the ones that crash have one. There is Filename and Copyright. I tried deleting just Filename and it displayed the way I wanted to. So if the script were changed to just delete the Filename data attribute, I think that would work.

This has been good for me, if nothing but to know how to set up a folder action. Quite interesting.

cwtnospam 01-13-2005 10:23 PM

Try this:
Put two dashes in front of the second delete command. That turns it into a comment, so it doesn't get executed. (Then save the script)

delete annotation annot1 in movie 1
--delete annotation annot2 in movie 1

schneb 01-14-2005 12:08 PM

I did that and it stopped crashing. I also commented out --set annot2 to "Copyright"

I drag 100 files in, it does about 3-4 files then stops.

cwtnospam 01-14-2005 12:56 PM

That's strange. I've just duplicated it on mine. For some reason, Quicktime quits. I'll see what I can do.

cwtnospam 01-14-2005 01:50 PM

It's definitely Quicktime unexpectedly quitting. I have been able to get it to do all of the 9 copies I made of the file, but with no significant changes to my code. Then I try it a second time and it crashes on the third file!

cwtnospam 01-14-2005 02:44 PM

Here's the latest. Quicktime is crashing on opening the file. The error log says:
Command: QuickTime Player
Path: /Applications/QuickTime Player.app/Contents/MacOS/QuickTime Player
Version: 6.5.2 (6.5.2)
PID: 2713
Thread: 0

Exception: EXC_BAD_ACCESS (0x0001)
Codes: KERN_PROTECTION_FAILURE (0x0002) at 0x0000002c

What's really strange about this is that is appears to be random, so I doubt it's the Applescript code. Anybody have any ideas?

The code:

on adding folder items to this_folder after receiving added_items
try
tell application "Finder"
set the folder_name to the name of this_folder
set l to the length of folder_name
set cpya to folder of this_folder
set cpy to ((cpya as string) & folder_name) as string
display dialog cpy
set ai to length of cpy
set annot1 to "Full Name"
set annot2 to "Copyright"
end tell
repeat with aItem in added_items
set lai to aItem as string
set la to length of lai
set adj to ai + 2
set fl to characters adj through la of lai as string
set fnm to cpy & "2:" & fl as string
tell application "Finder" to open aItem
tell application "QuickTime Player"
delete annotations in movie 1
save movie 1 in fnm
close movie 1 saving no
quit "QuickTime Player"
end tell
end repeat
end try
end adding folder items to

schneb 01-14-2005 04:00 PM

Again, worked a couple of times then, this time, got an unexpected error -600

Is it possible to make a droplet and save to another folder? I can hard-code in the location.

cwtnospam 01-14-2005 04:58 PM

Quote:

Originally Posted by schneb
Is it possible to make a droplet and save to another folder? I can hard-code in the location.

That's what the lines:

set fnm to cpy & "2:" & fl as string
and
save movie 1 in fnm

are for. It's to change the path from "~:folder:filename" to "!:folder2:filename"

Anyway, the problem is that Quicktime is crashing on opening the file, not saving it. It's weird because this test script to open and close each file, works:

on adding folder items to this_folder after receiving added_items
try
tell application "Finder"
repeat with aItem in added_items
open aItem
tell application "QuickTime Player"
close movie 1 saving no
end tell

end repeat
end tell
end try
end adding folder items to

cwtnospam 01-15-2005 02:08 AM

I think I've found the problem, although I don't yet have a solution. It seems that files with spaces in their names often affect not their own processing, but the next file to be opened and then saved. I think it's a bug in Applescript, because it doesn't always happen, especially if there is a delay such as that caused by a dialog or the command: delay 1



on adding folder items to this_folder after receiving added_items
tell application "Finder"
repeat with aItem in added_items
set nxtone to aItem as string
set lnxt to the length of nxtone
set flname to name of aItem as string
set lfln to length of flname
set ll to lfln as text
--activate
--display dialog "#" & flname & "#"
delay 1
open aItem
set adj to lnxt - lfln - 1
set cpy to characters 1 through adj of nxtone as string
set fnm to cpy & "2:" & flname as string
tell application "QuickTime Player"
delete annotations in movie 1
save movie 1 in fnm
close movie 1 saving no
end tell
end repeat
end tell
end adding folder items to


All times are GMT -5. The time now is 10:21 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.