Choose/Get commands, showing different results

Hi all,

I found I nice script that works ok and I want to adapt to my own needs.

The script asks for PDF files and then merge them into a new PDF file.

I need to select the files not by using a Choose command, but identifying them by name. I have a variable with the files correctly selected, but I´m getting an error.

This is the modified script:


set targetFolder to choose folder with prompt "Select the working folder"
set baseName to "2020-08-18" -- This variable comes from my main script, but I'm forcing a value here.

-- The following part is the original code that selects the PDF files
(*
display dialog "Please choose the files to merge…" default button "OK"
set inputFiles to choose file of type "PDF" with multiple selections allowed without invisibles
delay 0.25
*)
-- end of original code

-- This is my code to select files by name:
tell application "Finder" to set inputFiles to (get every file of folder targetFolder whose name contains baseName)
-- Another option
--tell application "Finder" to set inputFiles to (every file of folder targetFolder whose name contains baseName)
-- end of my code

display dialog "Type the name of the combined pdf: " default answer ""
set theName to text returned of the result
set outputFile to (targetFolder as text) & theName & "(" & (count of inputFiles) & "pages).pdf"

set pdfFiles to ""
repeat with p in inputFiles
	set pdfFiles to pdfFiles & " " & quoted form of POSIX path of p
end repeat

do shell script "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py " & "-o " & quoted form of POSIX path of outputFile & pdfFiles
return outputFile as alias

The error that I get with my code is:

It looks like it have to do with the name path, but I can’t figure it out where is the problem.
Thanks in advance for your help.

The choose file command in the original script returns aliases. The Finder returns Finder file specifiers, which POSIX path does not understand. Modify your script so that Finder returns aliases and the script works as expected on my computer.

For example:

set targetFolder to choose folder with prompt "Select the working folder"
set baseName to "2020-08-18" -- This variable comes from my main script, but I'm forcing a value here.

tell application "Finder"
	set inputFiles to (every file of folder targetFolder whose name contains baseName) as alias list
end tell

display dialog "Type the name of the combined pdf: " default answer ""
set theName to text returned of the result
set outputFile to (targetFolder as text) & theName & "(" & (count inputFiles) & "pages).pdf"

set pdfFiles to ""
repeat with p in inputFiles
	set pdfFiles to pdfFiles & " " & quoted form of POSIX path of p
end repeat

do shell script "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py " & "-o " & quoted form of POSIX path of outputFile & pdfFiles
return outputFile as alias

Working like a charm now.
Thanks Peavine!