Author Topic: Where to Start  (Read 2574 times)

0 Members and 1 Guest are viewing this topic.

Offline rayl

  • Newbie
  • *
  • Posts: 16
  • Karma: 0
  • Gender: Male
    • totalworks
Where to Start
« on: April 12, 2007, 12:16:56 PM »
Never have scripted Acrobat before, Applescript limited--big disapointment.

Found site that may be of help for users to try and use Javascript: www.acrobatusers.com/tech_corners/javascript_corner/

Have a need to batch print pdf's before they are sent along to printer. Boss, in my absence, used Acrobat batch print operation and of course output of list from Mac was unsorted. So I started working on a Applescript  sorted droplet to do job. Used modified file/folder droplet from Apple site which works well and sort routine from Rosenthal's book for folder list sort. On my MacBook with HP printer at home, the Acrobat print setup window comes up but needs return to proceed, then works fine. I tried using System Events then files printed auto but jobs did not close--strange Adobe behavior always when using System Events. Could use non-system method to send carrige return but syntax fails me at moment. Haven't tried on printers at work yet--been recovering from fall. Not sure if code will look OK always have trouble with color coding ap I have.

Code: [Select]
-- the list of file types which will be processed
-- eg: {"PICT", "JPEG", "TIFF", "GIFf"}
property type_list : {"PDF"}
-- since file types are optional in Mac OS X,
-- check the name extension if there is no file type
-- NOTE: do not use periods (.) with the items in the name extensions list
-- eg: {"txt", "text", "jpg", "jpeg"}, NOT: {".txt", ".text", ".jpg", ".jpeg"}
property extension_list : {"pdf"}

-- This droplet processes both files or folders of files dropped onto the applet
on open these_items
tell application "Finder"
sort these_items by name without invisibles
end tell
repeat with i from 1 to the count of these_items
set this_item to (item i of these_items)
set the item_info to info for this_item
if folder of the item_info is true then
process_folder(this_item)
else if (alias of the item_info is false) and
((the file type of the item_info is in the type_list) or
the name extension of the item_info is in the extension_list) then
process_item(this_item)
end if
end repeat
tell application "Finder"
activate
with timeout of 200 seconds --for those who don't pay attention
display dialog "Print PDF is Done" buttons {"OK"} default button 1
end timeout
end tell
end open

-- this sub-routine processes folders
on process_folder(this_folder)
set theList to list folder this_folder without invisibles

--sort folder list
repeat (length of theList) times
repeat with j from 1 to (length of theList) - 1
if item j of theList > item (j + 1) of theList then
set {item j of theList, item (j + 1) of theList} to
{item (j + 1) of theList, item j of theList}
end if
end repeat
end repeat

set these_items to theList
repeat with i from 1 to the count of these_items
set this_item to alias ((this_folder as text) & (item i of these_items))
set the item_info to info for this_item
if folder of the item_info is true then
process_folder(this_item)
else if (alias of the item_info is false) and
((the file type of the item_info is in the type_list) or
the name extension of the item_info is in the extension_list) then
process_item(this_item)
end if
end repeat
end process_folder

-- this sub-routine processes files
on process_item(this_item)
-- NOTE that the variable this_item is a file reference in alias format
-- FILE PROCESSING STATEMENTS GOES HERE
try
tell application "Printer Setup Utility"
set DefaultPrinter to the current printer
set current printer to printer "Photosmart C3100 series"
end tell

tell application "Adobe Acrobat 7.0 Professional"
activate
open file this_item
print this_item
close this_item saving no
end tell

tell application "Printer Setup Utility"
set current printer to printer DefaultPrinter
end tell

end try
end process_item
« Last Edit: April 12, 2007, 12:26:41 PM by rayl »
Raymond Lareine MacBook CoreDuo Mac OS 10.6.8 Totalworks (retired)

Offline larsen67

  • Sr. Member
  • ****
  • Posts: 459
  • Karma: 10
  • Gender: Male
Re: Where to Start
« Reply #1 on: April 18, 2007, 11:30:52 AM »
rayl, this prints the files fine for me if I change your "on process_item" to this:

001   on process_item(this_item)
002        -- NOTE that the variable this_item is a file reference in alias format
003        -- FILE PROCESSING STATEMENTS GOES HERE
004        try
005             tell application "Printer Setup Utility"
006                  set DefaultPrinter to the current printer
007                  set current printer to printer "DC_3535_DC3535_Print"
008             end tell
009             tell application "Adobe Acrobat 7.0 Pr#2CB915"
010                  activate
011                  open this_item
012                  tell active doc
013                       set PageCount to count of pages
014                       print pages first 1 last PageCount PS Level 3
015                  end tell
016                  close active doc saving no
017             end tell
018             tell application "Printer Setup Utility"
019                  set current printer to printer DefaultPrinter
020             end tell
021        end try
022   end process_item

I had to comment out lines 12, 13 & 14 of your code they would not work for me.

Offline rayl

  • Newbie
  • *
  • Posts: 16
  • Karma: 0
  • Gender: Male
    • totalworks
Re: Where to Start
« Reply #2 on: April 18, 2007, 07:43:56 PM »
Never sure of user behavior, lines 12-14 would sort some files if they were dropped on droplet from inside a folder besides insuring that a folder of folders would be processed in sorted order. PDF's are single page high res files that fit on one paper size. Droplet must run unattended. Below works if printer is setup correctly. Will modify and try your way also.

Quote
on process_item(this_item)
     -- NOTE that the variable this_item is a file reference in alias format
     -- FILE PROCESSING STATEMENTS GOES HERE
     try
          tell application "Printer Setup Utility"
               set DefaultPrinter to the current printer
               set current printer to printer "Photosmart C3100 series"
          end tell
         
          tell application "Adobe Acrobat 7.0 Professional"
               activate
               open this_item
               delay 2
               tell application "System Events"
                    tell process "Adobe Acrobat 7.0 Professional"
                         -- insert GUI Scripting statements here
                         click menu item 23 of menu 1 of menu bar item "File" of menu bar 1 --print
                         delay 2
                         key code 36 --send return
                         delay 2
                         click menu item 8 of menu 1 of menu bar item "File" of menu bar 1 --close file
                    end tell
               end tell
          end tell
         
          tell application "Printer Setup Utility"
               set current printer to printer DefaultPrinter
          end tell
         
     end try
end process_item

-------------------------
[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]



« Last Edit: April 18, 2007, 08:15:45 PM by rayl »
Raymond Lareine MacBook CoreDuo Mac OS 10.6.8 Totalworks (retired)

Offline larsen67

  • Sr. Member
  • ****
  • Posts: 459
  • Karma: 10
  • Gender: Male
Re: Where to Start
« Reply #3 on: April 19, 2007, 04:38:46 AM »
rayl, I had a quick look at why lines 12-14 wouldn't work for me and it appears that finder sort was re/introduced in Tiger & Im X.3.9