• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Folder Actions and File being written
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Folder Actions and File being written


  • Subject: Re: Folder Actions and File being written
  • From: Jim Skibbie <email@hidden>
  • Date: Mon, 23 Jun 2008 21:23:04 -0500
  • Thread-topic: Folder Actions and File being written

Title: Re: Folder Actions and File being written
Someone posted something similar to this a while back, check the archives. This is what I use to watch a folder that is having files FTP’ed into it. The guts of the watched folder is the repeat loop just after the set was, isNow to 0,1. It basically checks the size of the file and compares it to the size of the file 2 (or other defined time) seconds later. If the file has stabilized (e.g. It has stopped getting bigger), then the transmission is finished and the file can be picked up for processing.

set XML_In to "some:string:ofthefolder:location"

tell application "Finder"
    set foundfiles to (count files in folder (XML_In as string))
end tell

if foundfiles is greater than 0 then
   -- grab list of files for processing
   tell application "Finder"
        set XMLfiles to files in folder (XML_In as string)
    end tell
   
    repeat with i in XMLfiles
       tell application "Finder"
            set XMLpath to container of i as string
       end tell
       set AppleScript's text item delimiters to ":"
        set fileName to (text item -1 of i) as text
       set AppleScript's text item delimiters to ""
        set XMLAlias to (XMLpath & fileName) as alias
       -- loop to make sure the file has totally arrived (file size has stopped changing)
       set {was, isNow} to {0, 1}
        repeat while isNow ≠ was  --    <-- that’s a does not equal sign if it gets stripped out of the email
           set was to size of (info for (XMLAlias))
            delay 2 -- set this longer if the received file's transmission is slow
           set isNow to size of (info for (XMLAlias))
        end repeat
       --code of whatevery you're doing with the file
       -- i recommend moving the files one by one to a staging area to process
       --so in case there's an error, the file in the staging folder is
       --the one that needs to be processed still.
       tell application "Finder"
            set DocFileToTheStagingFile to move XMLAlias to folder XML_In_Staging with replacing
       end tell
       set thisFileName to (name of DocFileToTheStagingFile)
        set thisFileAlias to DocFileToTheStagingFile as alias
       set thisFilePosixPath to POSIX path of (thisFileAlias)
        set thisPosixFile to POSIX file thisFilePosixPath
       
        -- from here you should be able to insert whatever code you need to do whatever with each file
   end repeat
end
if
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Re: Applescript localization support
  • Next by Date: Re: Is Image Events working under Leopard?
  • Previous by thread: Re: Folder Actions and File being written
  • Next by thread: Mail crashing on mail action when getting content
  • Index(es):
    • Date
    • Thread