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