Newer
Older
Discussion_Papers / Other / Build DP.applescript
nstanger on 25 Mar 2003 2 KB Initial import of DPS stuff.
  1. -- Given a discussion paper in PDF format, insert the cover pages and generate a gzipped version.
  2. -- ALWAYS RUN THIS ON A COPY OF THE ORIGINAL FILE!
  3. --
  4. -- Assumptions:
  5. -- ¥ both the paper itself and the cover are in PDF form
  6. -- ¥ the paper is named "xxxx.pdf" (THIS WILL BE OVERWRITTEN)
  7. -- ¥ the cover is named "xxxx-cover.pdf"
  8. --
  9. -- For example, if the paper has the file name dp2000-10.pdf, the cover is assumed to be
  10. -- in dp2000-10-cover.pdf. Note that the final file will OVERWRITE the original, so don't use
  11. -- this script on the only copy!
  12. --
  13. -- Generally you will just drop the source file on the script and go have coffee.
  14.  
  15. global quitAcrobat
  16. global reportString
  17.  
  18. on open fileList
  19. my setup()
  20. repeat with theFile in fileList
  21. my process(theFile)
  22. end repeat
  23. my cleanup()
  24. end open
  25.  
  26. on run
  27. set theFile to choose file with prompt "Choose source file:"
  28. my process(theFile)
  29. end run
  30.  
  31. on setup()
  32. set reportString to ""
  33. tell application "System Events" to set quitAcrobat to not (exists process "Acrobat 5.0")
  34. end setup
  35.  
  36. on cleanup()
  37. activate
  38. display dialog reportString buttons {"OK"} default button "OK"
  39. if quitAcrobat then tell application "Waiareka HD:Applications:Adobe Acrobat 5.0:Acrobat 5.0" to quit
  40. end cleanup
  41.  
  42. on process(paperFile)
  43. set baseName to text 1 thru -5 of (paperFile as string)
  44. set coverFile to baseName & "-cover.pdf"
  45. set compressedFile to (paperFile as string) & ".gz"
  46. tell application "Waiareka HD:Applications:Adobe Acrobat 5.0:Acrobat 5.0"
  47. open alias coverFile with invisible
  48. set coverDoc to a reference to document 1
  49. open paperFile with invisible
  50. set paperDoc to a reference to document 2
  51. insert pages paperDoc after 0 from coverDoc starting with 1 number of pages 2
  52. close paperDoc saving yes with linearize
  53. close coverDoc saving no
  54. end tell
  55. do shell script "gzip -cf '" & (POSIX path of paperFile) & "' > '" & Â
  56. (POSIX path of compressedFile) & "'"
  57. set theSize to (do shell script "ls -l '" & (POSIX path of compressedFile) & Â
  58. "' | cut -d' ' -f8") as number
  59. tell application "Finder" to set theName to (displayed name of item compressedFile)
  60. if (reportString ­ "") then set reportString to reportString & return
  61. set reportString to reportString & theName & " is "
  62. if (theSize > 1048576) then
  63. set reportString to reportString & ((round (theSize / 1048576) rounding to nearest) / 10) & "MB."
  64. else
  65. set reportString to reportString & (round (theSize / 1024) rounding up) & "KB."
  66. end if
  67. end process