Q: Applescript move files to folder in specific order for Automator
Hi,
I have a script to do a bunch of stuff that makes PDF files that I stored into different folders. I want to be able to move items using a loop
i.e. repeat with i from 1 to (count of files in folder x) -- assuming all folders also have the same number of files
move item i of folder x to folder toCombine
move item i of folder y to folder toCombine
move item i of folder z to folder toCombine
tell application "combine"
run
end tell
end repeat
"Combine" is just a simple automator app that takes the folder contents of the folder "toCombine" and appends them in the order I want which is X > Y > Z as page 1,2 and 3. However, I see fluctuations in the order as I continue running to loop while looking at the folder toCombine, resulting in Z > Y > X and random orders.
I've added delay and even a check to see if there's item from X before moving item from Y etc.
Is there a workaround for this?
OS X El Capitan (10.11.4)
Posted on May 30, 2016 11:05 PM
Hi,
Solution:
Sort the list by name, like this:
--------
tell application "Finder"
set myList1 to sort (items of folder x) by name
set myList2 to sort (items of folder y) by name
set myList3 to sort (items of folder z) by name
repeat with i from 1 to (count myList1) -- assuming all folders also have the same number of files
move item i of myList1 to folder toCombine
move item i of myList2 to folder toCombine
move item i of myList3 to folder toCombine
tell application "combine"
run
end tell
end repeat
end tell
----------
Also, I tested in Automator, it returns the folder content in alphabetical order.
Otherwise, you must sort the items by name, just add the "Sort Finder Items" action after the "get folder content" action.
Posted on May 31, 2016 6:20 PM

