Folder Action and quicktime

Basically I need to batch convert mp3, wav and aiff file to aiff 48kHz 16bit stereo
i have a folder on my desktop called aifconvert to wich I attached this script

on adding folder items to this_folder after receiving added_item
	try
		tell application "QuickTime Player"
			launch
			activate
			stop every movie
			close every movie saving no
			open added_item
			copy name of added_item to newfilename
			export added_item as AIFF using most recent settings to file (newfilename & "aiff")
			close added_item
			quit
		end tell
	end try
end adding folder items to

the different file formats open but nothing happens i tried also to use this
export added_item as AIFF using settings preset “48 kHz 16 bit Stereo” to file (newfilename & “aiff”)

by the way i removed the s in added_items (since I’ll use the repeat possibilities once I’ll understand the syntax of applescript)
do I have to indicate an absolute path somewhere to create the file ?
and what about the export settings?
most recent settings appears in qt options but not 48 kHz 16 bit Stereo (but it doesn’t work with 44.1 either anyway)
I started applescript today so don’t assume I’ll understand all the cryptic habits that you may think of in your answer but I’ll do my best

thanx anyway I’ll dig this problems a bit deeper

Model: Dual 2.5 GHz Power PC G5
AppleScript: 1.10.6
Browser: Firefox 2.0
Operating System: Mac OS X (10.4)

Hi,

on adding folder items to this_folder after receiving added_items

returns a list of items, not a single item.
To process every file you need a repeat block

on adding folder items to this_folder after receiving added_items
    try
        tell application "QuickTime Player"
            -- launch (not necessary)
            activate
            stop every movie
            close every movie saving no
            repeat with this_item in added_items
                open this_item
                copy text 1 thru ((offset of "." in (name of (info for this_item))) - 1) of (name of (info for this_item)) to newfilename
                export movie 1 as AIFF using most recent settings to file (newfilename & ".aiff") -- only the filename will save the file on root level!
                close window 1
            end repeat
            quit
        end tell
    end try
end adding folder items to

works fine for me but as you say it saves the file at the root of the system I tried this
but it save the file with chinese character and no extensions
export movie 1 as AIFF using most recent settings to file {this_folder:(newfilename & “.aiff”)}

and I wonder also how to create settings for quicktime because I don’t want to use the most recent settings but 48kHz 16bit Stereo.
In the doc of quicktime it says that I can save settings but it appears nowhere

what does this means by the way ?

copy text 1 thru ((offset of “.” in (name of (info for this_item))) - 1) of (name of (info for this_item)) to newfilename

thanx a lot anyway you really helped me

you must specify a path:

... to file "Mac HD:Users:youruser:Documents:" & newfilename & ".aiff"

or

... to file (path to documents folder as string) & newfilename & ".aiff"

I never used that but it is described in the dictionary of QuickTime Player

this strips the filename from the extension

copy text 1 thru ((offset of “.” in (name of (info for this_item))) - 1) of (name of (info for this_item)) to newfilename

so the idea is to copy the name of the file until . with an offset of 1 so I don’t get the dot ?

A bit twisted but okay I get it

I know how to write down a path but I need to use the folder of the original audio file, I have a template of folder and subfolder that I use all the time in where there is a folder called mix to wich I want to attach the script, this template is duplicated for different project so the idea was to get the value of the container of the original audio file and find a way to paste it in the path of the export line

but still thank you so much

Saving a file into a folder where an AppleScript is attached to causes a never-ending loop,
because the handler detects a new file and starts the conversion and so on.

For this case I would use a droplet placed in the toolbar of a Finder window.
The path is always the folder displayed at the top of the window.
I changed the code (also for stripping the filename if there are multiple dots in the filename ;))
Save the script as an application an drag it into the toolbar (next to the search field) of some finder window.
Then drag the files onto the icon.

on open these_items
	tell application "Finder" to set destination to insertion location as string
	try
		tell application "QuickTime Player"
			activate
			stop every movie
			close every movie saving no
			repeat with this_item in these_items
				open this_item
				set {fName, fExt} to {name, name extension} of (info for this_item)
				copy destination & text 1 thru ((offset of fExt in fName) - 1) of fName & "aiff" to newfilename
				export movie 1 as AIFF using most recent settings to file newfilename
				close window 1
			end repeat
			quit
		end tell
	end try
end open

didn’t think of the loop… silly me

by the way I just modified your previous script to

export movie 1 as AIFF using most recent settings to file (newfilename & ".aiff")
save export settings movie 1 for AIFF to ("48test")

and now I can use this

export movie 1 as AIFF using settings "Tiger:mix:48test" to file (newfilename & ".aiff")

so now I don’t have to worry about the most recent settings
I use a file in wich is stored the settings I wanted

seems all the problems are solved now

thank you so much for your help I think my questions and your help will be very appreciated by the rest of the users in this forum

PS: Furthermore I would add a timeout block
to avoid a timeout error when converting large files

with timeout of 100000 seconds
export movie 1 as AIFF using settings “Tiger:mix:48test” to file (newfilename & “.aiff”)
end timeout

now that i understand how it works i created this script to automatically add a countdown and 1 secod of black to a movie for the sound studio we are working with (the countdown and the black are quicktime movie stored on ou server)

if any body needs the setup file for dvpal best quality or aiff 48khz 16bit stereo i don’t mind to upload or share them somwhere

thanx again

it’s like this

on open these_items
	tell application "Finder" to set destination to insertion location as string
	try
		tell application "QuickTime Player"
			activate
			stop every movie
			close every movie saving no
			repeat with this_item in these_items
				open "Volumes:ImageSAN_Public:HD-RORKE:_ID:Leader_Clips:Head_Leader_DV_PAL_24@25.mov"
				tell movie 1
					rewind
					select all
					copy
					select none
				end tell
				close movie 1 saving no
				open this_item
				tell movie 1
					select none
					rewind
					paste
					rewind
					select all
					copy
					select none
				end tell
				close movie 1 saving no
				open "Volumes:ImageSAN_Public:HD-RORKE:_ID:Leader_Clips:1sblack.mov"
				tell movie 1
					select none
					rewind
					paste
					select none
					rewind
					select at 0 to 0
				end tell
				set {fName, fExt} to {name, name extension} of (info for this_item)
				with timeout of 100000 seconds
					copy destination & text 1 thru ((offset of fExt in fName) - 1) of fName & "DVPAL" & ".mov" to newfilename
					export movie 1 as QuickTime movie using settings "Volumes:public:x_technic:dvpalsettings" to file newfilename
				end timeout
				close window 1
			end repeat
			quit
		end tell
	end try
end open