Print selected files with properties

Having trouble with this apple script below to print multiple pdf file with specific properties.

tell application "Finder"
set selectedFiles to selection as alias list
end tell

tell application "Fuji_Xerox_Colour"
print selectedFiles with properties {paper size:"A4"}
end tell

I get a syntax error when trying to compile on the first {.

Expected “given”, “with”, “without”, other parameter name, etc. but found “{”.

If I remove the

 with properties {paper size:"A4"}

It works but i need to make a few different scripts with different properties.

Any help appreciated.

Did you consult the application’s scripting dictionary?

I’m guessing print is a verb, so it cannot have properties.

print is a standard command that does have with properties argument:

but the standard print settings don’t have the paper size property.

so yes, @p_T should show us the dictionary to understand better what happens.

I’d argue that an argument is not a property. Nouns (objects) have properties. Verbs do not.

@ alastor933: I’m not exactly sure what’s your point but that’s how it works:

tell application "TextEdit" to print document 1 with properties {copies:1}

I dont seam to have the print settings link you have to see what you can set in my Script Editor Library?

Are you using a 3rd party editor or have missed something?
It would be a bit odd if you couldn’t set the paper size.

Apple’s standard print command is pretty limited and next to useless. it doesn’t have the paper size property.

individual apps can have their own print implementation with much more robust functionality.

my screenshot is from Script Editor.

what do you see in the dictionary of “Fuji_Xerox_Colour”?

Thanks @zevrix

Your right the print command is pretty much useless without being able to set the paper size.
Cant see anything more under the “Fuji_Xerox_Colour” dictionary.

I think I will have get the Apple Script to pass the files onto a shell command lp which looks like it can dictate the media size -o media=A4

This is what I have but getting an error.

error “lp: No such file or directory” number 1

tell application "Finder"
    	set selectedFiles to selection as alias list
    end tell

    set filePaths to {}
    repeat with thisFile in selectedFiles
    	set end of filePaths to quoted form of POSIX path of thisFile
    end repeat

    set printCommand to "lp -d Fuji_Xerox_Colour -o media=A4 " & filePaths as text

    do shell script printCommand

What does this return?

do shell script "which lp"

You may have an issue with filepaths as text as unless you set text delimiters to space, there will be nothing between the filenames being used.

That said, lp may have issues with printing multiple files with a single command.

Thanks @Mockman

Looks like my previous attempt was working but only for a single file not multiple selections.

tell application "Finder"
	set selectedFiles to selection as alias list
end tell

repeat with thisFile in selectedFiles
	set filePath to quoted form of POSIX path of thisFile
	set printCommand to "lp -d Fuji_Xerox_Colour -o media=A4 " & filePath
	do shell script printCommand
end repeat

The above apple script / shell script combo works with multiple files and will print everything to A4.
The lp shell command has alot more options that can be set. Far more than the Apple Script Print command.

My pleasure.

Here is a variation that should print multiple files while foregoing the applescript repeat loop. It requires that there be a space between file names (i.e. set delimiters to space). Basically, it runs the loop within the shell so there will only be a single instance of the shell.

set printCommand to "for f in " & filePaths & "; do lp -d Fuji_Xerox_Colour -o media=A4 \"$f\"; done"
1 Like

I think that in this scenario, the noun is print settings and the verb is print.

As @zevrix suggests, copies is a property of print settings but paper size is not.

Each application can provide its own settings. Applescript’s inherent print settings are lacking. I get the impression that they once put together a meagre package (although it does include fax number) that every app uses without changes. However, even an app with broken applescript support like Word can have a bucket of them including paper size (a property of page setup which is typically the property of a document).

yep AppleScript in Word is a mess.

the print command in Word is totally broken ever since Monterey. if you include with properties it will just return an error (and sometimes crash Word).

print out seems to work - even though it bears a note: “This command has been deprecated; use the Print command in the Standard Suite” (referring to the print command that’s now broken).

I’m still on Sierra so I am not exposed to these issues but really, I gotta blame them all on apple.

Part of the reason is that the paper sizes come from the printer description software and the names and sizes are not standardized.

Even “letter” and “legal” have different names and sizes in various printers.

It’s not completely useless, as it will not change the page size when you print. In most cases that means the printer will use the last size used. In some cases the printer will always revert to a default size.

A few years ago, when I wrote scripts that were printing to any one of a number of printers with various sizes the only way to automate that was to use UI scripting to change the Page Setup options.