Start printer if it is stopped and vice versa...

Hello,

Please excuse my posting in this forum without much knowledge of scripting in itself, however I am rapidly becoming an enthusiastic amateur.

I work at a university in what we like to call the digital darkroom where we have 10 large format printers constantly turning out images that the students are working on. Every now and again one of them will get its heads clogged and i have to run back to the office jump on the server and stop that printer from accepting anymore jobs until I have cleaned it.

I recently acquired an iPod Touch (read pinched of my girlfriend!) and subsequently have set up a mini wireless network in the suite with which I use a number of web apps to control various functions on the server so I can teach and administrate at the same time! Very clever we think, (probably not THAT clever in real life…) We wrote a bunch of individual Automator actions for each printer, one that starts a printer and one that stops a printer, which I can run using Blacktree’s Telekinesis app. http://www.blacktree.com/ I have them stored in two folder, start printer and stop printers. (It runs a shell script that reads “usr/bin/enable 10_4_3_1__IP” essentially.)

What I would love however and would make my life much easier is a script that can tell if the printer is enabled or disabled and put it into the opposite state, so that i can just have one button do the job of two. I would still need 10 buttons as Telekinesis does not show you the result so I cant enter numbers or text or anything. Each of the printers IP address’s start with 10.4.3. and then has its corresponding number at the end of the ip address 1 - 10. In PSU we have renamed them Printer_1 etc for simplicity.

This script looked like it might be possible to achieve my end result, http://macscripter.net/viewtopic.php?id=18548

Especially this bit…

if printerStatus contains "is not ready" then
   do shell script "/usr/bin/enable " & printerName
   pStat()
end if

and if anyone has the time to talk me through it i would be very grateful

So far I have

tell application "Printer_1"
	launch
        do shell script "usr/bin/enable _10_4_3_1__IP_"
end tell

But i defiantly need an “If”!

The other option i guess is to use the variable states in the new Automator in 10.5.x but i don’t know if they would run under 10.4.x

We are using OS X Server 10.4.11
2 x 3 GHz Dual-Core Intel Xeon

Many thanks in advance

Greg

(In a magical world where making iPhone apps is like using iLife! I wish i could have an app that when loaded it checks in with the server and gives me a list of printers that are currently on line, then when i select one i can control its functions from the phone. I sometimes use a VNC but it is a bit clumsy and not very flashy to look at. If i can nail this and somehow access our filemaker database as well I should be able to convince them in charge to buy all of us iPhones!)

Model: OS X Server 10.4.11
AppleScript: 2.1.1
Browser: Safari 525.27.1
Operating System: Mac OS X (10.4)

Hi,

this toggles the state of the current printer


tell (do shell script "/usr/bin/lpq") to set {printerName, isReady} to {word 1, paragraph 1 contains "is ready"}

if isReady then
	do shell script "/usr/sbin/cupsdisable " & printerName
else
	do shell script "/usr/sbin/cupsenable " & printerName
end if

Note: This works in Leopard, maybe on pre-Leopard systems you must use /usr/bin/enable and /usr/bin/disable

Brilliant,

Thank you Stephan. I’ll be in work by 9 so will check it out asap.

Thank you.

Greg

It very nearly works!

I’ve edited it slightly for 10.4 like you suggested and to force it to be a specific printer

tell application "Printer_1"
	tell (do shell script "/usr/bin/lpq") to set {printerName, isReady} to {word 1, paragraph 1 contains "is ready"}
	
	if isReady then
		do shell script "/usr/bin/disable " & printerName
	else
		do shell script "/usr/bin/enable " & printerName
	end if
	quit	
end tell

And this works great…

However I cant seem to get it to look at different printers? If I change the name to Printer_2 it opens and closes it but starts and stops Printer_1

Also is there a way to make it run in the background through terminal?

Thank you again

GReg

the application tell block is completely useless.
The name of the printer will be specified in the first shell script line.
But you can also do it this way for a certain printer


set printerName to "Printer_2"
if (do shell script "/usr/bin/lpq -P " & printerName) contains "is ready" then
	do shell script "/usr/bin/disable " & printerName
else
	do shell script "/usr/bin/enable " & printerName
end if

Hi Stefan,

That works great! I had to change the printerName to the IP address instead of the PSU name and it worked perfectly!

This is how it looks now

set printerName to "_10_4_3_3__IP_"
if (do shell script "/usr/bin/lpq -P " & printerName) contains "is ready" then
	do shell script "/usr/bin/disable " & printerName
else
	do shell script "/usr/bin/enable " & printerName
end if

Just out of interest, and i know my ipod wont display results, but is there a way of getting apple script to ask which printer i want to disable / enable?

Thanks for your help, I am now one step closer to getting all the staff here free ipods thanks to you!

Greg

try this


set thePrinters to choosePrinters()
if thePrinters is false then return
display dialog "enable or disable printer(s)" buttons {"Cancel", "Enable", "Disable"}
if button returned of the result is "Enable" then
	set command to "enable"
	set statusCheck to "is not ready"
else
	set command to "disable"
	set statusCheck to "is ready"
end if
repeat with onePrinter in thePrinters
	if (do shell script "/usr/bin/lpq -P " & onePrinter) contains statusCheck then
		do shell script "/usr/bin/" & command & space & onePrinter
	end if
end repeat

on choosePrinters()
	set printerList to paragraphs of (do shell script "/usr/bin/lpstat -a | /usr/bin/awk '{print $1}'")
	tell current application
		return (choose from list printerList with prompt "Please choose a printer" with multiple selections allowed)
	end tell
end choosePrinters

Incredible, it works like a charm!

Thank you Stefan, you’ve been amazing!

Greg