With Patch 6.2, my Automator / AppleScript got a workout! With repetition, found an issue. Apparently, not all AddOn authors follow the convention that the main folder contains both a .toc and a .lua file. So, instead of checking for .lua files, I'm now checking for .toc files. I had to switch around because while my Mac recognizes .lua as a valid extension, a .toc is not a registered extension so the older test failed. Now, I check that the file name contains (".toc".
Updated AppleScript
(* This script will process each item selected within Finder and process the item (assuming each item is an AddOn folder or a folder with a collection of AddOns).
With each folder in the selected items, check that the folder contains a file with the toc extension.
If the selected item (variable this_item) contains zero toc files then it is a parent folder containing multiple AddOns (like DBM). In this case, begin a second loop over the folders within the item (the variable more_items) and move each folder to the standard AddOns folder. Once all more_items are processed, the parent directory (this_item) is deleted from the source folder.
Hack: a move screws up the count of files so the more_items object is duplicated to the AddOns directory instead of being moved.
Otherwise, the selected item (this_item) contains one (or more) toc files and is considered a as a standalone AddOn, and is moved to the standard AddOns folder *)
on run {input, parameters}
tell application "Finder"
-- define desintation folder
set wow_addons_folder to folder "AddOns" of folder "Interface" of folder "World of Warcraft" of folder (path to applications folder) as alias
-- display dialog "wow_addons_folder: " & wow_addons_folder
set selected_items to selection
repeat with this_item in selected_items
-- display dialog "this_item: " & this_item
set this_item_alias to this_item as alias
-- count the children objects with a toc file extension
-- set number_of_files to count of (files in folder this_item_alias whose name extension is "lua")
set number_of_files to count of (files in folder this_item_alias whose name contains ".toc")
--display dialog "number_of_files: " & number_of_files
if number_of_files is equal to 0 then
-- no toc objects, so assume a parent addon folder containing a collection of stand alone addon files. start secondary looping
repeat with another_item in this_item
--display dialog "another item: " & another_item
--display dialog "Copying " & (name of another_item) & " to " & (name of wow_addons_folder)
-- hack: move screws up the count and causes errors. duplicate this object instead of moving it.
duplicate another_item to wow_addons_folder with replacing
end repeat
-- after processing each of the children, remove the parent object to avoid moving empty folders to addons folder
-- display dialog "deleting " & this_item
delete this_item
else
-- display dialog "Moving " & (name of this_item) & " to " & (name of wow_addons_folder)
move this_item to wow_addons_folder with replacing
end if
end repeat
end tell
return input
end run