Querying the Print Centre in 10.2.6
Querying the Print Centre in 10.2.6
- Subject: Querying the Print Centre in 10.2.6
- From: Paul Bunch <email@hidden>
- Date: Mon, 02 Jun 2003 20:56:49 +0100
Hello All,
A few days back I asked about querying the Print Centre. The ultimate
destination for this was to automate the batch printing of test-files across
popular applications.
The help I received enabled me to write the following (an example of use
with Text Edit), which I hope may be useful to someone else...
set folderpath to (choose folder) as string -- the file path as text
tell application "Finder"
activate
tell folder folderpath
try
set Tfilelist to (every file whose name contains ".rtf")
alias list
on error
set Tfilelist to (every file whose name contains ".rtf"),
as alias as list
end try
end tell
end tell
tell application "TextEdit"
activate
repeat with i from 1 to (count Tfilelist)
set testfile to item i of Tfilelist as string
open (testfile) as alias
delay 10
print (testfile) as alias
delay 1
tell application "Print Center"
repeat until status of current printer is printing
delay 1
end repeat
set jobName to (name of every job of current printer whose,
status is printing)
end tell
set logFile to open for access file,
"Macintosh HD:TestLogs:print list" with write permission
write ((jobName & return) as string) starting at,
((get eof logFile) + 1) to logFile
close access logFile
tell application "Print Center"
repeat until status of current printer is idle
delay 1
end repeat
end tell
activate
delay 10
try
close window 1 saving no
end try
end repeat
quit
end tell
delay 2
Andrew Oliver kindly answered my questions thus...
On 1/6/03 9:33 pm, "Andrew Oliver" <email@hidden> wrote:
>
Hey Paul,
>
>
The problem with your script is that there is no object called 'current job
>
name'. There isn't even a 'current job'. This is because jobs are associated
>
with specific printers - if you think about it, a busy print server could
>
have several print queues running, with different documents printing to each
>
on - which one is 'current'?
>
Therefore you have to be specific and tell AppleScript which printer you
>
want the current job of.
>
>
Additionally there's no 'current job', so you have to get all the jobs of a
>
particular printer and check for which one has the status 'printing'. A
>
little weird, but that's the way it works. :)
>
>
This seems to work for me:
>
>
(watch for line breaks)
>
>
tell application "Print Center"
>
set jobName to name of every job of current printer whose status is
>
printing
>
end tell
>
>
set logFile to open for access file "Disk:folder:print list" with write
>
permission
>
write ((jobName & return) as string) starting at ((get eof logFile)+ 1) to
>
logFile
>
close access logFile
>
>
>
Note that I'm not using TextEdit to write the list - that's more overhead
>
than you typically need. I'm just opening the log file (in this case
>
"Disk:folder:print list" and writing the data directly. I'm using "starting
>
at ((get eof logFile) + 1) to append the data to the end of the file,
>
otherwise it would start writing at the beginning, overwriting any existing
>
data).
>
>
Andrew
>
:)
>
>
>
On 6/1/03 5:04 AM, "Paul Bunch" <email@hidden> wrote:
>
>
> Hi Andrew,
>
> Thanks for your reply.
>
>
>
> I need to check it tomorrow, but I think I've tried this. What I actually
>
> want is two-fold.
>
> I also want to get the job name and write it to a log file, to record which
>
> files were successfully printed.
>
>
>
> Can I, for example..
>
> tell application "Print Center"
>
> get status of current printer
>
> get current job name as string
>
> set (My Job) to (current job name)
>
> end tell
>
>
>
> Then I need some way of passing the job name (provided it works) to TextEdit
>
> and writing to a file. Unfortunately everything I've tried has thrown up
>
> errors in one place or another.
>
>
>
> Paul
>
>
>
> On 1/6/03 6:14 am, "Andrew Oliver" <email@hidden> wrote:
>
>
>
>> You mean more than:
>
>>
>
>> tell application "Print Center"
>
>> get status of current printer
>
>> end tell
>
>>
>
>> Returns one of { stopped, idle, printing, error }, as appropriate
>
>>
>
>> Obviously you could query a specific printer given its name, or you could
>
>> check for any active printer using 'every printer', and walking the list
>
>> that's returned.
>
>>
>
>> Andrew
>
>> :)
>
>>
>
>> On 5/31/03 5:07 PM, "Paul Bunch" <email@hidden> wrote:
>
>>
>
>>> Hi People,
>
>>> Does anyone out there know how I can reliably query the default print queue
>
>>> (open default printer and/or query the process) under 10.2.6 (Beta System
>
>>> Events installed), as a means to set the length of delay between files,
>
>>> while batch printing?
>
>>>
>
>>> Regards,
>
>>> Paul Bunch
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.