How to make this AppleScript faster and better
Here's what I've got so far.
I will use this script a lot and with huge amount of files, so I need it to be perfect.
Unfortunately I am nothing at this kind of stuff, so a help would be really appreciated.
property source_folder : alias "path:to:source_folder:" as string property tattoos_folder : alias "path:to:tattoos_folder:" as string property models_folder : alias "path:to:models_folder:" as string property names_text : alias "OS X:Users:bagrov:Desktop:test:names.txt" as stringprocess_folder(source_folder)
on process_folder(this_folder)
set these_items to list folderthis_folder without invisibles set container_name to name of (info forthis_folder)
repeat with i from 1 to the count of these_items set this_item to alias ((this_folder as Unicode text) & (itemi of these_items))
if folder of (info forthis_item) is true then
process_folder(this_item)
else
process_item(this_item, container_name, i)
end if
end repeat
end process_folder-- this sub-routine processes files on process_item(this_item, c, i)
if i < 10 then
set i to "000" & i else if (i < 100) and (i > 9) then
set i to "00" & i else if (i < 1000) and (i > 99) then
set i to "0" & i end if
set r to (random numberfrom 0 to 9999)
if r < 10 then
set r to "000" & r else if (r < 100) and (r > 9) then
set r to "00" & r else if (r < 1000) and (r > 99) then
set r to "0" & r end if
tell application "System Events"
-- get file extension so not overwritten set e to name extension of this_item set new_name to "" & r & "" & c & "" & i & "." & e set name of this_item to new_name end tell
end process_item try
set names_list to paragraphs of (readfilenames_text)
tell application "Finder"
set item_list to (files of entire contents of foldersource_folder)
repeat with this_item in item_list set item_name to name of this_item repeat with this_name in name_list if this_name is in item_name then
movethis_itemtofoldermodels_folder exit repeat
end if
end repeat
if existsthis_item then movethis_itemtofoldertattoos_folder end repeat
end tell end trydisplay notification "All images were processed." with title "New" sound name "Glass.aiff"tell me to quit
I know that it's possible to make 'try' part better with shell. Finder won't get through 30,000-50,000 files.