Le 19/08/2015 à 13:30, Brian Christmas < email@hidden> a écrit :
G’day Yvan
That line was just left over from code I removed from the handler, that wasn’t relevant to my problem.
However, I think I’ve solved the question.
I’ve set the TextEdit page size to default to A4 by setting it in Page Setup, and saving it as the TextEdit Default, and then using this handler to set the CUPS printer to the large page printer. Also, I’ve set the System Preferences Printers & Scanners default printer to the 'Large Page Printer', and the default paper size to ‘A4’ (which will be ‘A3' on my Clients Mac.
try set nameOfPrinter to "" repeat with eachChar in characters of (theLargePagePrinter as text) —< ‘Large Page Printer' if eachChar = " " then set nameOfPrinter to nameOfPrinter & "_" as text else set nameOfPrinter to nameOfPrinter & eachChar as text end if end repeat do shell script ("lpoptions -d " & nameOfPrinter) end try
G'day Chris
On my side you code fails.
I was forced to edit an instruction to get a code doing the wanted job.
Look.
(1) Original :set theLargePagePrinter to "une grande imprimante"
set nameOfPrinter to "" try repeat with eachChar in characters of (theLargePagePrinter as text) --< ‘Large Page Printer' if eachChar = " " then set nameOfPrinter to nameOfPrinter & "_" as text else set nameOfPrinter to nameOfPrinter & eachChar as text end if end repeat end try
nameOfPrinter -- > "une grande imprimante"
(2) Edited version :
set theLargePagePrinter to "une grande imprimante"
set nameOfPrinter to "" try repeat with eachChar in characters of (theLargePagePrinter as text) --< ‘Large Page Printer' if contents of eachChar = " " then set nameOfPrinter to nameOfPrinter & "_" as text else set nameOfPrinter to nameOfPrinter & eachChar as text end if end repeat end try
nameOfPrinter -- > "une_grande_imprimante"
(3) On my side, I avoid character like the plague and would use :
set theLargePagePrinter to "une grande imprimante"
set nameOfPrinter to "" try repeat with eachChar in text of (theLargePagePrinter as text) --< ‘Large Page Printer' if contents of eachChar = " " then set nameOfPrinter to nameOfPrinter & "_" as text else set nameOfPrinter to nameOfPrinter & eachChar as text end if end repeat end try
nameOfPrinter -- > "une_grande_imprimante"
(4) As I am lazy, I would not write a new code using a loop when I have a handler using TIDS for this task
set theLargePagePrinter to "une grande imprimante"
set nameOfPrinter to my remplace(theLargePagePrinter, space, "_") nameOfPrinter -- > "une_grande_imprimante"
#===== (* replaces every occurences of d1 by d2 in the text t *) on remplace(t, d1, d2) local oTIDs, l set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d1} set l to text items of t set AppleScript's text item delimiters to d2 set t to l as text set AppleScript's text item delimiters to oTIDs return t end remplace
#=====
(5) When I want to display a dialog, I don't trigger "System Events" but "SystemUIServer" Maybe somebody will be able to explain what are the advantages of each of them;
Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) mercredi 19 août 2015 14:13:07
|