Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

property disk : "Webserver:RAID:active_jobs" -- name of mounted disk where all work resides property folderactive : "Active" -- name of Folder were active jobs folders are held property destination : "_xFiles" -- name of subfolder were files are placed within job folder

on adding folder items to this_folder after receiving these_items

    set the these_items to list folder this_folder without invisibles
    set this_folder to this_folder as string

    -- find search string (Job Number in our case)
    repeat with i from 1 to number of items in these_items
        set this_item to item i of these_items
        set this_item to this_item as string
        set this_item to (this_folder & this_item) as alias
        set the item_info to the info for this_item
        set the item_name to the name of item_info

        -- determine length of job number 
        set the stringlength to text 5 of the item_name
        if the stringlength is equal to "_" then
            set the search_name to text 1 thru 4 of the item_name
            set the search_name to text 1 thru 5 of the item_name
        end if

        -- path to active_jobs:Active
        set the source_folder to (disk & ":" & folderactive) as alias

        -- lists contents of Active before starting search
        set the job_list to list folder source_folder without invisibles
        set source_folder to source_folder as string

        -- look through all active jobs
        repeat with i from 1 to number of items in the job_list
            set this_job to item i of the job_list
            set this_job to (source_folder & this_job) as alias
            set job_info to info for this_job
            set the current_name to the name of job_info
            set change_flag to false

            -- Compares folder name to search string
            if the current_name contains the search_name then
                set the change_flag to true

                -- Once found, target folder is set
                if the change_flag is true then
                    set this_job to this_job as string
                    set final_path to (this_job & destination) as alias

                    -- Place files inside it's own job folder
                    tell application "Finder"
                        move this_item to folder final_path with replacing
                    end tell

                    -- Moves on to next file to be moved
                    exit repeat
                end if
            end if
        end repeat
    end repeat

on error error_message number error_number
    tell application "Finder"
        display dialog error_message buttons {"Cancel"} default button 1 giving up after 120
    end tell
end try

end adding folder items to

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.