Print A Window

In the OS9 finder you could select the menu item “Print Window” under the “File” menu to get a file list print out of a given window. I used a script in OS9 to perform this task for many years. My question is how do you print a window in OSX? Does anyone have a script example to show how this is possible?

Any information would be greatly appreciated,
CarbonQuark

Unfortunately, the “print window” feature is gone. The easiest way to do it now is to open the window you want, hit command-shift-4 and then tap the spacebar. When the icon changes to a camera, click on the window you want. It will take a screen shot of just that window. In Panther it will save it as a PDF and in Tinger it will save it as a PNG file. You have to open this up and print it out in Preview or Acrobat Reader or Photoshop.

There is also a utility called “Print Window”. You can find it on VersionTracker.com if you want the old OS9 style printing. The basic version is freeware. I find the printout a little ugly and difficult to customize so I prefer the screenshot technique. You may like Print Window better though.

As far as scripting, either of these might be difficult to script.

Matt-Boy,

Thanks for the info… I have been using command-shift-4… but I didn’t know about the spacebar… Thanks for the tidbit.

CarbonQuark

If I hit “command-shift-4” then “space bar” and then hold “control” when I click the window it copies the image of the window to the clipboard instead of saving it to a file. I could then script print the clipboard… I will post the script once I have it working.

If anyone else has a better idea let me know,
CarbonQuark

Hi,

You could also use the selection property and ui scripting. I think what you’re trying to do is get an outline listing and that would need a listtle more scripting to create the outline.

Basically, to get the selected list from the window:

tell application "Finder" to activate
tell application "System Events"
	tell process "Finder"
		keystroke "a" with command down -- change 'with' to 'using' post Jaguar
		keystroke "c" with command down
	end tell
end tell

This should get a listing of a window in ‘list’ view. There is nothing to designate the child items. This is the part that needs scripting.

Write back with more info.

gl,

Kel,

I thought about doing it this way… but a screen capture of the window is probably the easiest method (gets icons and properties in a single step). I am still trying to figure out how to print a screen capture that resides on the clipboard.

Thanks,
CarbonQuark

I just recently wanted to do the same thing - grab a select window, as an image, direct to the clipboard.
Here’s what I’m using:


do shell script "screencapture -iwc"

For more info on the specific flags, take a look at the man pages for screencapture.

Mark

Once you take that screen shot and it saves a PDF on your desktop, you can (at least in my experience) just drag that PDF onto your printer icon in the Printer List. You don’t have to actually launch Acrobat or Preview to print it. This is probably just as fast as making an AppleScript to print the PDF or to print the clipboard if you got the screen shot image on the clipboard.

I have scripted sending a PDF on the desktop directly to a printer but I’m not sure how one might use that in this situation. Here it is if you want to experiment:

set PathToDesktop to path to the desktop as text
set thisPath to POSIX path of file (PathToDesktop & filename & ".pdf") as string
set theShell to ("lpr -P " & PrinterNameAsItAppearsInPrinterList & " " & thisPath & " -o media=letter")
do shell script theShell

Model: Mac G5 OS 10.3.9
Operating System: Mac OS X (10.3.9)

Thanks for the info Matt-Boy & mleslie - CarbonQuark

Hello All,

Here is my final script:


tell application "Finder"
	activate
	try
		set sidebar width of window 1 to 0
		set current view of Finder window 1 to list view
		set position of Finder window 1 to {10, 55}
		set bounds of Finder window 1 to {10, 55, 100, 100}
		set properties of list view options of Finder window 1 to {calculates folder sizes:false, icon size:small, sort column:name column, uses relative dates:false}
		set properties of column name column of list view options of Finder window 1 to {width:275, visible:true}
		set properties of column modification date column of list view options of Finder window 1 to {width:150, visible:true}
		set properties of column size column of list view options of Finder window 1 to {width:90, visible:true}
		set properties of column kind column of list view options of Finder window 1 to {width:250, visible:true}
		set the visible of column label column of list view options of Finder window 1 to false
		set the visible of column version column of list view options of Finder window 1 to false
		set the visible of column comment column of list view options of Finder window 1 to false
		set the visible of column creation date column of list view options of Finder window 1 to false
		select every item of front window
		tell application "System Events" to keystroke (ASCII character 29) using {option down}
		tell application "System Events" to tell process "Finder" to click button 2 of window 1
		delay 0.1
		set selection to {}
	on error
		display dialog "Please open a finder window" buttons "Cancel"
	end try
end tell

do shell script "screencapture -iW ~/Documents/printwindow.png"

tell application "Safari"
	activate
	open file "Users:Baugh:Documents:printwindow.png"
	do shell script "lpoptions -d hp_color_LaserJet_5550_"
	print document 1
	close document 1
end tell

If you see any problems or a better way to do this let me know… Thanks,
CarbonQuark

I put in my user name and commented out

do shell script "lpoptions -d hp_color_LaserJet_5550_"

I got a print of my window. Nifty. Of course, I randomly chose a window with far too many files to all fit in the window.

This script will be a good reference for me. Thanks,

j

Hello All,

What do I need to add to this script so that I can drag a folder to it and it will print the window?

tell application "Finder"
   activate
   try
       set sidebar width of window 1 to 0
       set current view of Finder window 1 to list view
       set position of Finder window 1 to {10, 55}
       set bounds of Finder window 1 to {10, 55, 100, 100}
       set properties of list view options of Finder window 1 to {calculates folder sizes:false, icon size:small, sort column:name column, uses relative dates:false}
       set properties of column name column of list view options of Finder window 1 to {width:275, visible:true}
       set properties of column modification date column of list view options of Finder window 1 to {width:150, visible:true}
       set properties of column size column of list view options of Finder window 1 to {width:90, visible:true}
       set properties of column kind column of list view options of Finder window 1 to {width:250, visible:true}
       set the visible of column label column of list view options of Finder window 1 to false
       set the visible of column version column of list view options of Finder window 1 to false
       set the visible of column comment column of list view options of Finder window 1 to false
       set the visible of column creation date column of list view options of Finder window 1 to false
       select every item of front window
       tell application "System Events" to keystroke (ASCII character 29) using {option down}
       tell application "System Events" to tell process "Finder" to click button 2 of window 1
       delay 0.1
       set selection to {}
   on error
       display dialog "Please open a finder window" buttons "Cancel"
   end try
end tell

do shell script "screencapture -iW ~/Documents/printwindow.png"

tell application "Safari"
   activate
   open file "Users:Baugh:Documents:printwindow.png"
   do shell script "lpoptions -d hp_color_LaserJet_5550_"
   print document 1
   close document 1
end tell

Thanks,
Carbon Quark