Trouble processing mutliple files in a dir w/ Folder Actions

Hi, im trying to create a peice of applescript that will process a file, create a new file, open it in a specific application then print the file saving it with the name of the original file that was dropped into the folder.

everything works as it should except it only works on 1 item in the folder then stops processing.
The other question i would have is how would i go about making this a Droplet?
here is the code i am using now,

the original code (that is commented out at the bottom) did process mutliple .job files, but i think that was becuase it ran all of the time (the repeate while true part)


<?php
--set jobPath to location of Preps .job saved from UpFront ( You will need to create a folder and change this path ) 
property donePath : "Preps 2:Users:Plateroom:Desktop:Done:" 
property TemplatePath : "Preps 2:Templates:Templates:Auto Template:" 
property jobsPath : "Preps 2:Script:Jobs:" 
--set pjtfPath to location for Preps to create PJTF ( You will need to create a folder and change this path ) 
property pjtfPath : "Preps 2:Users:Plateroom:Desktop:PJTF:" 

on adding folder items to this_folder after receiving these_items 
    -- create directories if they dont exist 
    tell application "Finder" 
        if not (exists folder donePath) then 
            make new folder at desktop with properties {name:"Done"} 
        end if 
        if not (exists folder jobsPath) then 
            make new folder at "Preps 2:Script:" with properties {name:"Jobs"} 
        end if 
        if not (exists folder pjtfPath) then 
            make new folder at desktop with properties {name:"PJTF"} 
        end if 
    end tell 
     
    tell application "Finder" 
        -- Right here i want it to loop through all of the items in the list. 
        if exists item 1 of this_folder then 
             
            -- i need a configuration setting from Preps 
            tell application "Preps 5" 
                set MarksPath to marks and templates path 
            end tell 
             
            set TemplateName to name of item 1 of this_folder 
             
            set DeviceType to do shell script ("php -e /Script/template.php '" & TemplatePath & "' '" & TemplateName & "' '" & MarksPath & "'") 
            -- this is a hack for the intermediate file. 
            -- the do shell script above created a file named 
            --  template_name.job. We then need to open that up in preps. 

            set jobName to TemplateName & ".job" 
            open item jobName of folder jobsPath 
             
            -- wait 5 seconds to allow preps to open the job 
            do shell script "sleep 2" 
             
            -- this is no longer needed because we set the  
            -- template name then append the .job to it later 
            --set outName to do shell script ("echo " & outName & "  |sed 's/.job//g' ") 

            -- print the PJTF to the pjtfpath as set above and close the job 
            tell application "Preps 5" 
                print the front job to device DeviceType saving as job ticket saving in pjtfPath filename TemplateName 
                close the front job 
            end tell 
             
            -- delete the intermediate file 
            delete item jobName of folder jobsPath 
             
        end if 
        -- move the template out of there so it isnt processed again. 
        move item 1 of this_folder to donePath 
    end tell 
end adding folder items to 


-- This is the orignal script in which i built the above from. 
(* 
repeat while true 
    tell application "Finder" 
         
        -- check if we have a job to open and open it. Set the name of the pjtf to the job name 
        if exists item 1 of folder TemplatePath then 
            tell application "Preps 5" 
                set MarksPath to marks and templates path 
            end tell 
             
            set TemplateName to name of item 1 of folder TemplatePath 
             
            set DeviceType to do shell script ("php -e /Script/template.php '" & TemplatePath & "' '" & TemplateName & "' '" & MarksPath & "'") 
            --display dialog JobName 
             
            -- open the first item we find in the folder 
            open item 1 of folder jobsPath 
             
            -- wait 5 seconds to allow preps to open the job 
            do shell script "sleep 2" 
            --set outName to do shell script ("echo " & outName & "  |sed 's/.job//g' ") 
            -- print the PJTF to the pjtfpath as set above and close the job 
            tell application "Preps 5" 
                print the front job to device DeviceType saving as job ticket saving in pjtfPath filename TemplateName 
                close the front job 
            end tell 
             
            -- move the processed item so we don't open it again 
            delete item 1 of folder jobsPath 
            move item 1 of folder TemplatePath to donePath 
        end if 
    end tell 
end repeat 
*)
?> 

Thanks

Your script only works on the first item because you specifically process only the first item in the folder, completely ignoring anything dropped on the script:

Instead you need to iterate through the items that were dropped:

 on adding folder items to this_folder after receiving these_items
   repeat with each_item in these_items
   if exists each_item -- not really necessary since the item has to exist - it was dropped on the script
...
... and
   set TemplateName to name of each_item

and so on.

you rock man, that works perfecly.
had another bug with some extra whitespace in my device name, but another search in this forum turned up a trim method that works as needed.

the other question about creating a droplet, im sure that’d be just a simple change of

on adding folder items to this_folder after receiving these_items

to
on adding dropped_items to ??? after ???

??

and im sure that i’d have to remove the
move item 1 of this_folder to donePath
line because there wouldnt be an item to move

thanks again

Ok, im a step closer. I installed X-tools and created a Droplet project.

However, my script requires a full path to the template, as seen in these lines

property TemplatePath : “Preps 2:Templates:Templates:Auto Template:”
set DeviceType to do shell script (“php -e /Script/template.php '” & TemplatePath & “’ '” & TemplateName & “’ '” & MarksPath & “'”)

Since i need to know the location of the template for my php script, in the droplet, what would i use to get the folder of the dropped file(s)

Thanks

To write the script as a droplet you use the ‘on open’ handler:

on open these_items
 ...
end open 

As with folder actions, these_items is a list of the items fropped on the script.

For a start, do shell script requires Unix-style paths, so Mac-style (colon-delimited) paths will not work.

For the rest, do you mean that you’re trying to determine the path of the file dropped on the script? If so, that’s easy to do using the ‘posix path’ command which takes care of converting Mac-style paths to Unix paths. Additionally you should use ‘quoted form of’ the path to make sure it’s shell-safe (properly quoted/escaped)

on open dropped_items
  repeat with each_item in dropped_items
      set filePath to posix path of each_item as text
      do shell script "php -e /Script/template.php " & quoted form of filePath & " '" & MarksPath & "'"
end repeat
end open

but I’m not entirely sure on what your ‘do shell script’ is supposed to do to know if this is the correct syntax for you or not.