I need to create an application or folder action where users can drop files. The folder will then:
- Check the first 13 digits of each filename and create a new directory using those 13 digits
- Move all files with the same first 13 digits in to the relevant folder
- Move the whole folder to a preset directory on the server
JPG names will be:
- 00319-BB01-01-C1 HighResDig.jpg 00319-BB01-01-C1 HighResPrint.jpg
- 00319-BB01-01-C1 LowResDig.jpg 00319-BB01-01-C1 AI.jpg
- 00319-BB01-01-C1 Catalogue.jpg 00319-BB01-01-C1 Web.jpg
- 00319-BB01-01-S1 HighResDig.jpg 00319-BB01-01-S1 HighResPrint.jpg
- 00319-BB01-01-S1 LowResDig.jpg 00319-BB01-01-S1 AI.jpg
- 00319-BB01-01-S1 Catalogue.jpg 00319-BB01-01-S1 Web.jpg
- 00319-BB01-01-S2 HighResDig.jpg 00319-BB01-01-S2 HighResPrint.jpg
- 00319-BB01-01-S2 LowResDig.jpg 00319-BB01-01-S2 AI.jpg
- 00319-BB01-01-S2 Catalogue.jpg 00319-BB01-01-S2 Web.jpg
- 00320-BB01-01-C1 HighResDig.jpg 00320-BB01-01-C1 HighResPrint.jpg
- 00320-BB01-01-C1 LowResDig.jpg 00320-BB01-01-C1 AI.jpg
- 00320-BB01-01-C1 Catalogue.jpg 00320-BB01-01-C1 Web.jpg
- 00320-BB01-01-S1 HighResDig.jpg 00320-BB01-01-S1 HighResPrint.jpg
- 00320-BB01-01-S1 LowResDig.jpg 00320-BB01-01-S1 AI.jpg
- 00320-BB01-01-S1 Catalogue.jpg 00320-BB01-01-S1 Web.jpg
- 00320-BB01-01-S2 HighResDig.jpg 00320-BB01-01-S2 HighResPrint.jpg
- 00320-BB01-01-S2 LowResDig.jpg 00320-BB01-01-S2 AI.jpg
- 00320-BB01-01-S2 Catalogue.jpg 00320-BB01-01-S2 Web.jpg
At the moment, the JPGs are being created automatically using a Photoshop Droplet. The droplet then creates a directory on the users desktop with all versions of the file. This folder is called JPGs.
It would be useful if I could create a folder action for the Desktop>JPGs folder to then automatically run the script to create the new directory and move the files. Creating the files can take between 2 seconds and 1 minute depending on how many are being created at once.
I have some partially working code to create the new folders, but I cannot get it to automatically run based using a folder action in Automator
on run {input, parameters}
set chosenFolder to (choose folder)
tell application "Finder" to set fileList to files of (chosenFolder)
repeat with aFile in fileList
set {name:Nm, name extension:Ex} to info for (aFile as alias)
if Ex is missing value then set Ex to ""
if Ex is not "" then set Nm to text 1 thru ((count Nm) - (count Ex) - 1) of Nm
set dateFolder to text 1 thru 13 of Nm
set sourceFile to quoted form of POSIX path of (aFile as text)
set destinationFile to quoted form of (POSIX path of chosenFolder & dateFolder & "/" & name of aFile)
do shell script "ditto " & sourceFile & space & destinationFile
do shell script "rm " & sourceFile
end repeat
end run
This creates a new folder and moves the correct files. I need this to run automatically when files are dropped in to a specific folder. I then need to move the newly created folders to another directory.
2
Answers
You can move the folder with
And what is going to happen if two files are distributed in the same dateFolder? The syntax above will overwrite an existing folder.
For a folder action you actually don’t need an automator workflow.
You can do this with folder actions, without using Automator. Open the Script Editor app and copy in the following code:
Save it with whatever name you like in ‘~/Library/Scripts/Folder Action Scripts‘. Open the Folder Actions Setup app, click the ‘+’ button on the left to add your JPGs folder and the ‘+’ button on the right to attach the script to the folder. Then you should be done.
P.s. If you need to set up the folder action programmatically — for instance, if you’re setting these up manually and not just cloning a user — you can use a script like this:
You can change ‘ask’ in the last line to ‘yes’ or ‘no’, depending on whether you want to automatically process items already in the folder.