Convert to AIFF Folder Action
Convert to AIFF Folder Action
- Subject: Convert to AIFF Folder Action
- From: Peter Baxter <email@hidden>
- Date: Tue, 26 Sep 2006 09:49:01 +1000
The email got too big to post with all the replies so here is the
final script which works.
property done_foldername : "AIF Files"
property originals_foldername : "Original Files"
property newimage_extension : "aif"
property type_list : {"mp3", "mov"}
property extension_list : {"mp3", "mov"}
on adding folder items to this_folder after receiving these_items
tell application "Finder"
if not (exists folder done_foldername of this_folder) then
make new folder at this_folder with properties {name:done_foldername}
end if
set the results_folder to (folder done_foldername of this_folder)
as alias
if not (exists folder originals_foldername of this_folder) then
make new folder at this_folder with properties
{name:originals_foldername}
set current view of container window of this_folder to list view
end if
set the originals_folder to folder originals_foldername of this_folder
end tell
try
repeat with i from 1 to number of items in these_items
set this_item to item i of these_items
set the item_info to the info for this_item
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
tell application "Finder"
my resolve_conflicts(this_item, originals_folder, "")
set the new_name to my resolve_conflicts(this_item,
results_folder, newimage_extension)
set the source_file to (move this_item to the originals_folder
with replacing) as alias
end tell
process_item(source_file, new_name, results_folder)
end if
end repeat
on error error_message number error_number
if the error_number is not -128 then
tell application "Finder"
activate
display dialog error_message buttons {"Cancel"} default button 1
giving up after 120
end tell
end if
end try
end adding folder items to
on resolve_conflicts(this_item, target_folder, new_extension)
tell application "Finder"
set the file_name to the name of this_item
set file_extension to the name extension of this_item
if the file_extension is "" then
set the trimmed_name to the file_name
else
set the trimmed_name to text 1 thru -((length of file_extension) +
2) of the file_name
end if
if the new_extension is "" then
set target_name to file_name
set target_extension to file_extension
else
set target_extension to new_extension
set target_name to (the trimmed_name & "." & target_extension) as
string
end if
if (exists document file target_name of target_folder) then
set the name_increment to 1
repeat
set the new_name to (the trimmed_name & "." & (name_increment as
string) & "." & target_extension) as string
if not (exists document file new_name of the target_folder) then
-- rename to conflicting file
set the name of document file target_name of the target_folder
to the new_name
exit repeat
else
set the name_increment to the name_increment + 1
end if
end repeat
end if
end tell
return the target_name
end resolve_conflicts
on process_item(source_file, new_name, results_folder)
try
set the source_item to the quoted form of the POSIX path of the
source_file
set the target_path to the quoted form of the POSIX path of
(((results_folder as string) & new_name) as string)
with timeout of 900 seconds
tell application "QuickTime Player"
activate
open source_file
try
if not (exists movie 1) then error "No movies are open."
stop every movie
set QT_version to (QuickTime version as string)
set player_version to (version as string)
if (QT_version is less than "6.0") or ¬
(player_version is less than "6.0") then
error "This script requires QuickTime 6.0 or greater." & ¬
return & return & ¬
"Current QuickTime Version: " & QT_version & return & ¬
"Current QuickTime Player Version: " & player_version
end if
if QuickTime Pro installed is false then
set the target_URL to "http://www.apple.com/quicktime/download/"
display dialog "This script requires QuickTime Pro." & return &
return & ¬
"If this computer is currently connected to the Internet, " & ¬
"click the “Upgrade” button to visit the QuickTime Website
at:" & ¬
return & return & target_URL buttons {"Upgrade", "Cancel"}
default button 2
ignoring application responses
tell application "Finder"
open location target_URL
end tell
end ignoring
error number -128
end if
set the movie_name to the name of movie 1
if (can export movie 1 as AIFF) is true then
set the new_file to ¬
choose file name with prompt "Enter a name and choose a
location for the new file:" default name movie_name
export movie 1 to new_file as AIFF
close movie 1
else
error "This movie cannot be exported as an AIFF file."
end if
on error error_message number error_number
if the error_number is not -128 then
beep
display dialog error_message buttons {"Cancel"} default button 1
end if
end try
end tell
end timeout
on error error_message
tell application "Finder"
activate
display dialog error_message buttons {"Cancel"} default button 1
giving up after 120
end tell
end try
end process_item
Peter Baxter
email@hidden
iChat email@hidden
Peter Baxter
email@hidden
iChat email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden