Is there a way to have a Folder Action make a list of files that are dropped into it, then have the items removed from the list once they appear in another specified location?
Much appreciated,
slimjim
Is there a way to have a Folder Action make a list of files that are dropped into it, then have the items removed from the list once they appear in another specified location?
Much appreciated,
slimjim
Does “once they appear in another…” mean they are moved out of the folder with the listing action?
Correct. What I’m looking to do is set up a “Process” folder. When items are dropped in the Process folder, the folder will remember the file names then copy them to a specific “In” folder on a network. When the files are color corrected and appear in the “Out” folder, they need to be copied to a specific place on my HD. Once a file is copied from the network, the list can disregard that file.
Still not entirely clear, SlimJim. Is the “Process” folder on your machine or the “network”? Is “on a network” code for a machine elsewhere or for a shared folder on your machine? How do the files get into the “In” folder? Do you intend to poll the “Out” folder periodically to see if its contents have changed and then move them? Sorry for all the questions.
I welcome the questions NovaScotian, I just appreciate the help.
I currently have a “Raw Folder” on my HD with original JPEGs in it which I drop into an “In Folder” on a network. The images are color corrected, saved as EPS files to an “Out Folder” on the network. Once they appear there. I drag them to a “Fixed Folder” on my HD which kicks off an Applescript that performs some operations to the file names and deletes the file from the Network “Out Folder”.
People other than myself use the In and Out Folders on the network so somehow the Applescript needs to know if the files are mine or not. I want the Applescript to watch the “Out Folder” for me and if one of my files appears in it, copy it to my “Fixed Folder” on my HD. I can’t attach a Folder Action to the Network folders, so that’s where I came up with the “Process Folder” idea.
The “Process Folder” will reside on my HD. When I drop files into it, the script will make a list of the added files and copy the files to the Network “In Folder”. When the corrected files appear in the “Out Folder”, if the file name is on the list, it will copy it to my “Fixed Folder” on my HD. Once the file is copied from the “Out Folder” it can be removed from the list. Does this make more sense?
Now it makes perfect sense. I’ll think on it.
I just thought of an easier solution to bypass the list theory. When the file is dropped into the “Process Folder” the AS inserts text “Loaded by Slimjim” into the file’s Comment field. Now the question is, can script then watch the “Out Folder” on the network for files with comment marked “Loaded by Slimjim” and copy only these files to my “Fixed Folder” on my HD?
That is easier. You can get the path to the file by mounting the external volume and then using “choose file” in a separate mini-script. Before doing anything else in this file check that it exists (boolean). Then tell the Finder to get comment of yourFile and you’re done, test that, move the file in the finder and you’re done. You would put this in an idle handler and leave it running in the background. If you inadvertently closed the server, your test for exists could post a dialog for you (or reopen the connection). Lots of examples of all of this here.
Wonderful Adam! I really appreciate your help! I’m gonna start working on the script tomorrow as it is almost Drinking, I mean, Quitting time.
Slimjim
Just an update…
I came up with an awesome solution for my situation only to realize that the when the file appears in the network’s Outbox, the comments have been stripped off and are then locked and therefore unditable. But at least my test script works…
on idle
set OutBox to "Macintosh HD:Users:Admin:Desktop:TestOutBox"
tell application "Finder"
repeat with thisFile in folder OutBox
if comment of thisFile contains "Loaded by Jason" then
copy thisFile to folder "Macintosh HD:Users:Admin:Desktop:TestFixed"
set comment of thisFile to "Already Copied"
end if
end repeat
end tell
return 60 * 1
end idle
The whole idea relys on the comment saying “Loaded by Jason” and to keep from copying files several times, I need to be able to edit the comment to “Already copied”.
Oh well, back to the drawing board.
From what I understand of the workflow that you are working with you probably want to create an “Agent” using an on idle handler rather than a folder action. The reason is that you need something to watch for the files once you have moved them to the network. Adding comments, as you have discovered, isn’t reliable becouse the people doing the color corection are probably doing a save as and wiping out the comments, or the network is wiping them out for some reason.
What might work best is to write a log file in the same location as the script. Then when the idle handler is initiated it can load the text from the log file into a string, move any files that are done, then delete those moved items from the list and update the log file with the new list.
So I got this script to work in my test environment, however, I need some help on two things…
property ProcessFolder : "Macintosh HD:Users:Admin:Desktop:Testprocess"
property OutBoxFolder : "Macintosh HD:Users:Admin:Desktop:TestOutbox"
property FixedFolder : "Macintosh HD:Users:Admin:Desktop:TestFixed"
set ProcessList to {}
set ProcessTemp to {}
tell application "Finder" to set ProcessNames to name of files of folder ProcessFolder
repeat with i from 1 to (count ProcessNames)
set ProcessTemp's end to (item i of ProcessNames)
end repeat
set ProcessList to ProcessTemp
repeat with i from 1 to (count of ProcessList)
set the_item to (item i of ProcessList) as string
if (exists (OutBoxFolder & "the_item")) then
tell application "Finder"
try
set CopyFile to (OutBoxFolder & ":" & the_item)
set DeleteFile to (ProcessFolder & ":" & the_item)
duplicate file (CopyFile) to folder (FixedFolder) replacing yes
delete file (DeleteFile)
end try
end tell
end if
end repeat
Problem # 1 When I move this into production, the OutBoxFolder is actually two different locations.
Should I just duplicate that section of the script to look in the second location or can I refer to two separate locations at once?
Problem # 2 The files in ProcessFolder are JPGs. In the real OutBoxes, the JPGs will be turned into EPS files.
Can I change the items in ProcessList to list the items without .JPG at the end? Or make the last four characters invisible or irrelevant?
Thanks for any guidance you can offer!
Slim;
A few little things occur to me at a glance:
You "tell application “Finder” to set aNameList to name of every file in folder “soAndso”. AppleScript has a command for doing that: “set aNameList to list folder (path to soAndso) without invisibles”. The second of these is quicker since it doesn’t require interaction with another application.
I’m assuming that Question 1 arises because two other machines will both have OutBoxen. The usual way to manage that is to make your collector a handler with the address to the machine as an argument and you have the handler return the names to your main script. Then in your main script, you call this for each location and deal with the rest.
The names of the files are just text that happen to include a period: “myPicture.jpg”. This is one of many ways to address that:
set myFileName to "myPic.jpg"
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."
set fileBase to text item 1 of myFileName
set AppleScript's text item delimiters to TID -- put them back the way they were.
set myFileName to fileBase & ".tif"
In addition, see this thread, particularly the second post by hhas: http://bbs.applescript.net/viewtopic.php?id=15062
I tried and tried to get this to work to no avail, I guess I don’t understand Handlers/Arguments well enough.
I was able to get this script to work until I tried to save it as a Stay Open Application. It errors out saying that it does not understand the “exists” message (does this need to be within the “Tell Finder” block?) Did I even set it up correctly to use as a Stay Open App that runs every minute?
property ProcessFolder : "Macintosh HD:Users:Admin:Desktop:Testprocess"
property OutBoxFolder1 : "DDNAdvertising:Out:CMYK"
property OutBoxFolder2 : "DDNAdvertising:Out:Grayscale"
property FixedFolder : "Macintosh HD:Users:Admin:Documents:RE Photos:Fixed RE Photos"
on idle
set ProcessNames to {}
set ProcessTemp to {}
set ProcessNames to list folder (ProcessFolder)
repeat with i from 1 to (count ProcessNames)
set ProcessTemp's end to (item i of ProcessNames)
end repeat
set ProcessList to ProcessTemp
repeat with i from 1 to (count of ProcessList)
set the_item to (item i of ProcessList) as string
if (exists (OutBoxFolder1 & "the_item")) then
tell application "Finder"
set myFileName to the_item
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."
set fileBase to text item 1 of the_item
set AppleScript's text item delimiters to TID
set the_item2 to fileBase & ".EPS"
try
set CopyFile to (OutBoxFolder1 & ":" & the_item2)
set DeleteFile to (ProcessFolder & ":" & the_item)
duplicate file (CopyFile) to folder (FixedFolder) replacing yes
delete file (DeleteFile)
end try
end tell
end if
end repeat
repeat with i from 1 to (count of ProcessList)
set the_item to (item i of ProcessList) as string
if (exists (OutBoxFolder2 & "the_item")) then
tell application "Finder"
set myFileName to the_item
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."
set fileBase to text item 1 of the_item
set AppleScript's text item delimiters to TID
set the_item2 to fileBase & ".EPS"
try
set CopyFile to (OutBoxFolder2 & ":" & the_item2)
set DeleteFile to (ProcessFolder & ":" & the_item)
duplicate file (CopyFile) to folder (FixedFolder) replacing yes
delete file (DeleteFile)
end try
end tell
end if
end repeat
return 60 * 1
end idle
As you can see, the bottom portion is totally redundant. I don’t know how to make the “if exists” statement look at both OutBoxFolders.
Close to giving up,
slimjim5811