OK, here is what I am trying to do. I am trying to move files (digital images) from folder A to folder B.
Folder A is a local folder that is shared out as a server volume. Other machines write to it.
Folder B is a server that puts digital images into a digital archive system. the images, once processed by the system. are automatically removed from Folder B.
The reason for this script is that our OSX boxes will not properly write to the input server “folder B” So we have to build a gateway of sorts where the OSX machines can write to Folder A (on an OS9 box) and then the script will move the files in to the server.
The operation must operate unattended.
I have built a simple script that selects all files in Folder A, copies them to folder B and then deletes them from folder A. It works great.
There are two problems. The server that houses folder B is slow and if it takes too long to transfer files the script times out, stopping the rest of the procedure. Therefore causing the files to not get deleted and the process copys the same files over and over into the archive (not good). Is there a way that I can tell the applet not to time out or to reset the timeout to 999 mins or something?
the second problem is that I am using MacSchedule to run the applet every 5 mins. Is there a way to do this in applescript? to repeat the process every five minutes until someone quits the program??
I know this is long, but I wanted you to have the details. I am using Apple Script Editor to write/record the script and this is my very first attempt at writing applescript.
The check syntax is giving me an error on the “end timeout” “expected tell, etc. but found timeout”
Again, this is my first time writing applets and my first programming adventure in a long time (I am a photographer my profession). If there are any other things I have done wrong please let me know!
Thank you for your patience,
Shane Bevel
Staff Photojournalist
The Times
[/quote]
on idle
with timeout of 2000 seconds
tell application “Finder”
activate
select every item of container window of folder “OSX Drop Box”
copy selection to disk “Local Photos”
delete selection
empty trash
return 300
end tell
end timeout
end idle
Here is the final code for anyone interested. It seems to work great!
Glad to help. Here’s a modified version that doesn’t rely on selected items or an open window. I generally try to avoid working on selections since a selection can be changed by a user during the execution of the script. This can can cause unexpected/undesired results. You’ll need to provide the full path to “OSX Drop Box”.
on idle
tell application "Finder"
set items_ to items of folder "path:to:OSX Drop Box"
with timeout of 2000 seconds
duplicate items_ to disk "Local Photos"
end timeout
delete items_
empty trash
end tell
return 300
end idle
Again, I am new, so maybe I am reading the code wrong.
But I think that if during the copy process from OSX Drop Box to Local Photos someone was to write a file to OSX Drop Box via the network then that photo would be deleted without being copied to Local Photos.
Also, this is more or less a dedicated server. There are no users on the box. But I do understand that if I select something while the program is copying files it will be deleted instead of the copied files.
My version of the script gets a list of the items that are present in OSX Drop Box at execution time. This list is saved to a variable (items_), creating a virtual snapshot of the items in the folder at that point in time. From that point forward, the script will work only on the items in the list - not all of the items in the folder. Anything that arrives after the list is generated will be handled on the next execution of the script.
With that said, and now that you’ve been warned of possible consequences, it’s your call on the best way to proceed.