I have had a request where I need to select a folder which contains subfolders, which inside, have either one or more pdf’s.
I have found a fantastic command line package (joinpdf) which is part of the itext project, which can join the pdf’s, but I am fairly green at this intense level of applescript.
The way I was tackling this problem was to set up a repeat command to query the subfolders, and then in this repeat, get the joinpdf command to create a pdf under the chosen folder with the name of the folder containing all the pdf’s i was trying to join. My stumbling block is getting the names of these files to come out in a order similar to this “/pathtochosenfolder/chosenfolder/subfolder1/1.pdf /pathtochosenfolder/chosenfolder/subfolder1/2.pdf, etc, etc” as the joinpdf command works like this joinpdf /pattochosenfolder/subfoldername.pdf /pathtochosenfolder/chosenfolder/subfolder1/1.pdf /pathtochosenfolder/chosenfolder/subfolder1/2.pdf, etc, etc" with spaces between the pdf’s being to separate arguments. So far, this is my applescript for getting information on the folders and files, but I cannot seem to get my head around how I can achieve my goal. Any help is more than appreciated.
on run
global sourcefolder
set sourcefolder to choose folder
global sub_folders
set sub_folders to {}
set the_folder_list to list folder sourcefolder without invisibles
set the_count to count of the_folder_list
repeat with i from 1 to number of items in the_folder_list
set this_items to item i of the_folder_list
set folder_action to this_items
set initial_source to sourcefolder & this_items & ":" as string
set kachup to initial_source
set sub_cat to this_items & ":" as string
set inforec to info for file (initial_source)
if (kind of inforec) is "folder" then set end of sub_folders to (name of inforec)
set the_files to {}
--tell application "Finder" to set folder_list to entire contents of folder folder_action & ":"
tell application "Finder"
set allFiles to {}
set allFiles to (files of entire contents of alias kachup whose name extension is "pdf")
end tell
repeat with i from 1 to number of items in allFiles
set name_step to {}
set name_step to name of item i of allFiles
end repeat
end repeat
end run