Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > AppleScript: on arrival of a file...

AppleScript: on arrival of a file...
Thread Tools
Fresh-Faced Recruit
Join Date: Feb 2004
Status: Offline
Reply With Quote
Feb 5, 2005, 05:38 PM
 
My server FTP's me backups every so often. I want to move these into a folder based on the date. I've got it working, sort of, using the following code:

on adding folder items to this_folder after receiving these_items
tell application "Finder"
if not (exists folder "Done" of this_folder) then
make new folder at this_folder with properties {name:"Done"}
end if
set the destination_folder to folder "Done" of this_folder as alias
set the destination_directory to POSIX path of the destination_folder
end tell
repeat with i from 1 to number of items in these_items
set this_item to item i of these_items
set the item_info to info for this_item
if this_item is not the destination_folder and the name extension of ¬
the item_info is not in {"zip", "sit"} then
set the item_path to the quoted form of the POSIX path of this_item
set the destination_path to the quoted form of ¬
(destination_directory & (name of the item_info) & ".zip")
do shell script ("/usr/bin/ditto -c -k -rsrc --keepParent " & ¬
item_path & " " & destination_path)
end if
end repeat
end adding folder items to
that code's directly from an apple example page.

The problem: it takes time for the file to complete uploading to me. Folder actions seems to stop paying attention to the file by the time the uploading is complete. Is there any way to get around this...?
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Feb 5, 2005, 05:58 PM
 
Possibly... (I can't guarantee that this will work)

You could have the folder action script trigger another script (an applet)

This second applet could have an "on idle" handler - which means it runs repeatedly, with a pause of your choosing between each execution.

The applet script could have a few 'properties', which will persist across the executions.

You could use these properties in the idle handler to check to see if the downloaded file hasn't got any bigger (i.e. the download has finished) - when that happens rename the file and move it to the right place, then get the Applet to quit itself.
You know it makes sense. ☼ ☼ ☼ Growl.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 07:09 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2