Chris
Chris

Reputation: 25

how to create and send output directly to printer using do shell script

I am trying to get a shell script that works in the sh shell to work as an applescript do shell script command. The script simply takes a series of elp2 commands and pipes them to lpr for printing. This works when typed directly into the shell, but when run in applescript it does not print. The printer is receiving data but it is not formated correctly so nothing prints. I believe the issue is with the way the quotes are escaped. Here is the code:

do shell script "{ echo N
echo OD10
echo q812
echo Q1218,24
echo D15
echo ZT
echo A70,40,0,5,3,3,N,\\'F\\'
echo A610,70,0,3,1,1,N,\\'U.S.\\'
echo A590,95,0,3,1,1,N,\\'POSTAGE\\'
echo A580,120,0,3,1,1,N,\\'REQUIRED\\'
echo A43,240,0,4,2,1,N,\\'USPS FIRST-CLASS MAIL\\'
echo A43,300,0,3,1,1,N,\\'Name\\'
echo A43,325,0,3,1,1,N,\\'street\\'
echo A43,350,0,3,1,1,N,\\'city, VA 12345\\'
echo A43,400,0,3,1,1,N,\\'ADDRESS SERVICE REQUESTED\\'
echo A140,490,0,4,1,1,N,\\'ship to\\'
echo A140,520,0,4,1,1,N,\\'company\\'
echo A140,550,0,4,1,1,N,\\'address\\'
echo A140,580,0,4,1,1,N,\\'city, state, 12345\\'
echo A140,610,0,4,1,1,N,\\'country\\'
echo A140,640,0,4,1,1,N,\\'\\'
echo LO10,10,760,4
echo LO10,210,760,2
echo LO10,275,760,2
echo LO10,750,760,10
echo LO10,1050,760,10
echo LO10,1185,760,4
echo LO10,10,4,1175
echo LO770,10,4,1175
echo LO210,10,2,200
echo LO540,45,200,2
echo LO540,45,2,125
echo LO540,170,200,2
echo LO740,45,2,125
echo P1
echo N;} | lpr -P Label -o raw"

Upvotes: 0

Views: 209

Answers (1)

regulus6633
regulus6633

Reputation: 19030

One way you can check how to write something in applescript is to write the normal unescaped text into a text file. Then you read the file into applescript. What you see in the result field is how you should write it. You can then copy/paste the result into your applescript.

For example, if I make a text file on my desktop called myText.txt with this inside...

echo A70,40,0,5,3,3,N,\'F\'
echo A610,70,0,3,1,1,N,\'U.S.\'

Then I use this applescript...

set f to (path to desktop as text) & "myText.txt"
read file f

My result is...

"echo A70,40,0,5,3,3,N,\\'F\\'
echo A610,70,0,3,1,1,N,\\'U.S.\\'"

So give that technique a try with your entire code. Good luck.

Upvotes: 2

Related Questions