Newer
Older
Discussion_Papers / Other / Build DP.applescript
nstanger on 25 Mar 2003 2 KB Initial import of DPS stuff.
-- Given a discussion paper in PDF format, insert the cover pages and generate a gzipped version.
-- ALWAYS RUN THIS ON A COPY OF THE ORIGINAL FILE!
--
-- Assumptions: 
--	¥ both the paper itself and the cover are in PDF form
--	¥ the paper is named "xxxx.pdf" (THIS WILL BE OVERWRITTEN)
--	¥ the cover is named "xxxx-cover.pdf"
--
-- For example, if the paper has the file name dp2000-10.pdf, the cover is assumed to be
-- in dp2000-10-cover.pdf. Note that the final file will OVERWRITE the original, so don't use
-- this script on the only copy!
--
-- Generally you will just drop the source file on the script and go have coffee.

global quitAcrobat
global reportString

on open fileList
	my setup()
	repeat with theFile in fileList
		my process(theFile)
	end repeat
	my cleanup()
end open

on run
	set theFile to choose file with prompt "Choose source file:"
	my process(theFile)
end run

on setup()
	set reportString to ""
	tell application "System Events" to set quitAcrobat to not (exists process "Acrobat 5.0")
end setup

on cleanup()
	activate
	display dialog reportString buttons {"OK"} default button "OK"
	if quitAcrobat then tell application "Waiareka HD:Applications:Adobe Acrobat 5.0:Acrobat 5.0" to quit
end cleanup

on process(paperFile)
	set baseName to text 1 thru -5 of (paperFile as string)
	set coverFile to baseName & "-cover.pdf"
	set compressedFile to (paperFile as string) & ".gz"
	
	tell application "Waiareka HD:Applications:Adobe Acrobat 5.0:Acrobat 5.0"
		open alias coverFile with invisible
		set coverDoc to a reference to document 1
		open paperFile with invisible
		set paperDoc to a reference to document 2
		insert pages paperDoc after 0 from coverDoc starting with 1 number of pages 2
		close paperDoc saving yes with linearize
		close coverDoc saving no
	end tell
	
	do shell script "gzip -cf '" & (POSIX path of paperFile) & "' > '" & Â
		(POSIX path of compressedFile) & "'"
	set theSize to (do shell script "ls -l '" & (POSIX path of compressedFile) & Â
		"' | cut -d' ' -f8") as number
	
	tell application "Finder" to set theName to (displayed name of item compressedFile)
	
	if (reportString ­ "") then set reportString to reportString & return
	set reportString to reportString & theName & " is "
	if (theSize > 1048576) then
		set reportString to reportString & ((round (theSize / 1048576) rounding to nearest) / 10) & "MB."
	else
		set reportString to reportString & (round (theSize / 1024) rounding up) & "KB."
	end if
end process