Ok, a little background about this script. I AM NOT a professional programmer or scripter. I am a designer who does applescript as a hobby/personal interest. The place where I work wanted an easy way to deliver PDF proofs for our clients to view in a web interface without requiring the customer to log in (php/MYSql). So I wrote this script that allows that. It takes the frontmost indesign doc, makes a pdf of it, reformats a template html and php file, and uploads the folder to our web server. Then it sends a notification to the customer. It also records data in a file that can be accessed later if the file is sent as a revision. This way you don’t have to type things twice. This script works fine on my Leopard machine but fails when it tries to create the data file on the desktop in Tiger. It says “Can’t make “desktop” into type constant.” Anybody have any ideas about how to solve this? I have marked the part of the script where it fails.
tell application "Adobe InDesign CS3"
if (count documents) = 0 then -- no InDesign documents open
display dialog "There is no active InDesign document. You must have an InDesign document open to run this script." buttons " OK " default button 1 with icon caution
else if (count documents) is greater than 1 then -- more than one InDesign document open
display dialog "You must have only one InDesign document open to run this script." buttons " OK " default button 1 with icon caution
else --> continue with the script if document requirements are met
tell application "Adobe InDesign CS3" -- make the current InDesign document into a PDF and save it to the desktop
set myPDFPresetName to "[Smallest File Size]" -- this can be whichever PDF preset you want to use
set myPDFName to "ad_proof_th.pdf"
set frontDoc to name of front document
set myPDF to ((path to desktop) & myPDFName) as string
save front document
tell front document
export format "Adobe PDF" to myPDF using myPDFPresetName without showing options
close frontDoc
end tell
end tell
--> begin core script <--
tell application "Finder"
activate
display dialog "Is this a first proof or a revision?" buttons {"Revision", "First Proof"} default button 2
end tell
--> button clicked is "Revision"
if button returned of result is "Revision" then
tell application "Finder"
activate
display dialog "Enter the job jacket number for the proof you want to revise." default answer "" buttons {"Cancel", "Continue"} default button 2
set jobJacketNumber to text returned of result
end tell
tell application "Finder"
if exists (folder jobJacketNumber of folder "active" of disk "proofs") then
tell application "Finder"
set theFolder to (folder jobJacketNumber of folder "active" of disk "proofs")
set pathToMe to ((container of theFolder as Unicode text) & jobJacketNumber & ":WPDATA.dat")
end tell
set myList to (read file pathToMe using delimiter "+")
set myParsedList to myList as list
set repEmail to item 1 of myParsedList
set theAddress to item 2 of myParsedList
set bizName to item 3 of myParsedList
tell application "Finder"
set revisedPDF to document file "ad_proof_th.pdf" --revised pdf file sitting on the desktop
move revisedPDF to folder jobJacketNumber of folder "active" of disk "proofs" with replacing -- move it to its new home and replace the old pdf
move revisedPDF to trash --and then trash it so it doesn't sit on the desktop
end tell
set webAddress to {"http://www.newnan.com/proofs/active/" & jobJacketNumber & "/"} as string
set noticeMessage to ({"Dear " & bizName & ","} as string) & return & return & "Your ad proof has been revised. To view your revised proof, click on the link below:" & return & return & webAddress & return & return & "This e-mail was generated by an automated process. Please do not reply to it."
-- the message subject
set theSubject to "Your Times-Herald Ad Proof Has Been Revised"
-- the body of the message
set theBody to noticeMessage
set theSender to "WebProof<proofs@newnan.com>"
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:theSubject, content:theBody & return & return}
tell newMessage
set visible to true
set sender to theSender
make new to recipient at end of to recipients with properties {address:theAddress}
-- Bring the new compose window to the foreground, in all its glory
activate
send newMessage
delay 1
--this generates an email to the ad rep letting them know their proof has been sent
set repNotifyAddress to repEmail
set repNotifySubject to ({"A REVISED proof has been sent to "} & bizName) as string
set repNotifyBody to (({"The Customer: " & bizName} as string) & " Job Jacket Number: " & jobJacketNumber) as string
tell application "Mail"
set newRepNotifyMessage to make new outgoing message with properties {subject:repNotifySubject, content:repNotifyBody & return & return}
tell newRepNotifyMessage
set visible to true
set sender to theSender
make new recipient at end of to recipients with properties {address:repEmail}
activate
send newRepNotifyMessage
end tell
end tell
end tell
end tell
else if (exists folder jobJacketNumber of folder "active" of disk "proofs") = false then --> job jacket number failed
tell application "Finder"
activate
display dialog "Sorry, but the job jacket number you entered does not exist in the proofing system." buttons "OK" default button 1 with icon caution
move document file "ad_proof_th.pdf" to trash
end tell
end if --> job jacket check
end tell --> job jacket check
--> button clicked is "First Proof"
else if button returned of result is "First Proof" then
tell application "Finder"
display dialog "What is the job jacket number?" default answer ""
set jobJacketNumber to text returned of the result
end tell
tell application "Finder"
if (exists folder jobJacketNumber of folder "active" of disk "proofs") = false then --> job jacket check
set listOfReps to {"Candy Johnson", "Doug Cantrell", "Rosemary Reid", "Christine Swentor", "Stefanie Dowda", "Jeanette Kirby", "Lamar Truitt"}
tell application "Finder"
activate
set adRep to item 1 of (choose from list listOfReps with prompt "Which ad rep is this for?")
end tell
if (text of adRep = "Lamar Truitt") then
set repEmail to "lamar@newnan.com"
else
if (text of adRep = "Jeanette Kirby") then
set repEmail to "jeanette@newnan.com"
else
if (text of adRep = "Stefanie Dowda") then
set repEmail to "stefanie@newnan.com"
else
if (text of adRep = "Christine Swentor") then
set repEmail to "christine@newnan.com"
else
if (text of adRep = "Rosemary Reid") then
set repEmail to "rosemary@newnan.com"
else
if (text of adRep = "Doug Cantrell") then
set repEmail to "doug@newnan.com"
else
if (text of adRep = "Candy Johnson") then
set repEmail to "candy@newnan.com"
end if
end if
end if
end if
end if
end if
end if
if (text of adRep = "Lamar Truitt") then
set repCell to "404-788-3259"
else
if (text of adRep = "Jeanette Kirby") then
set repCell to "N/A"
else
if (text of adRep = "Stefanie Dowda") then
set repCell to "404-788-3246"
else
if (text of adRep = "Christine Swentor") then
set repCell to "404-788-3242"
else
if (text of adRep = "Rosemary Reid") then
set repCell to "404-788-3263"
else
if (text of adRep = "Doug Cantrell") then
set repCell to "404-788-3235"
else
if (text of adRep = "Candy Johnson") then
set repCell to "404-788-3258"
end if
end if
end if
end if
end if
end if
end if
repeat
tell application "Finder"
activate
set theResult to display dialog "What is the customer's email address?" default answer ""
set theAddress to text returned of theResult
end tell
if theAddress does not contain "@" then
tell application "Finder"
activate
display dialog {"You have entered an invalid email address."} buttons "Try Again" default button 1 with icon caution
end tell
else if theAddress contains "@" then
exit repeat
end if
end repeat
tell application "Finder"
duplicate folder "-nth" of folder "WebProof Source" of disk "Server 1 HD1" to desktop
move file "ad_proof_th.pdf" to folder "-nth"
end tell
tell application "Finder"
display dialog "What is the name of the customer's business?" default answer ""
set bizName to text returned of the result
end tell
--> create and write WPDATA.dat
set thePath to ((path to desktop) as Unicode text) & "WPDATA.dat" (**************** THE SCRIPT FAILS HERE *******************)
set fRef to (open for access file thePath with write permission)
try
write repEmail & "+" & theAddress & "+" & bizName to fRef
end try
close access fRef
tell application "Finder"
set name of folder "-nth" to jobJacketNumber
move file "WPDATA.dat" to folder jobJacketNumber
end tell
tell application "Finder"
set myIndexFile to document file "index.html" of folder jobJacketNumber
set myPHPFile to document file "contact.php" of folder jobJacketNumber
end tell
tell application "TextWrangler"
activate
open myIndexFile
open myPHPFile
replace "bizName" using bizName saving yes searching in {every text document} options {search mode:literal, case sensitive:false, match words:true, extend selection:false, showing results:false}
replace "jobJacketNumber" using jobJacketNumber saving yes searching in {every text document} options {search mode:literal, case sensitive:false, match words:true, extend selection:false, showing results:false}
replace "adRep" using adRep saving yes searching in {every text document} options {search mode:literal, case sensitive:false, match words:true, extend selection:false, showing results:false}
replace "repEmail" using repEmail saving yes searching in {every text document} options {search mode:literal, case sensitive:false, match words:true, extend selection:false, showing results:false}
replace "repCell" using repCell saving yes searching in {every text document} options {search mode:literal, case sensitive:false, match words:true, extend selection:false, showing results:false}
replace "theAddress" using theAddress saving yes searching in {every text document} options {search mode:literal, case sensitive:false, match words:true, extend selection:false, showing results:false}
save {text document "index.html"}
save {text document "contact.php"}
close {text document "index.html"}
close {text document "contact.php"}
end tell
tell application "Finder"
move folder jobJacketNumber to folder "active" of disk "proofs"
move folder jobJacketNumber to trash
end tell
-- an email message to the client
set webAddress to {"http://www.newnan.com/proofs/active/" & jobJacketNumber & "/"} as string
set noticeMessage to ({"Dear " & bizName & ","} as string) & return & return & "Your ad is now available for viewing. To view your proof, click on the link below:" & return & return & webAddress & return & return & "This e-mail was generated by an automated process. Please do not reply to it."
-- the message subject
set theSubject to "Your Times-Herald Ad Proof Is Now Available"
-- the body of the message
set theBody to noticeMessage
set theSender to "WebProof<proofs@newnan.com>"
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:theSubject, content:theBody & return & return}
tell newMessage
set visible to true
set sender to theSender
make new to recipient at end of to recipients with properties {address:theAddress}
-- Bring the new compose window to the foreground, in all its glory
activate
send newMessage
delay 1
--and now, one for the ad reps
set repNotifyAddress to repEmail
set repNotifySubject to ({"A proof has been sent to "} & bizName) as string
set repNotifyBody to (({"The Customer: " & bizName} as string) & " Job Jacket Number: " & jobJacketNumber) as string
tell application "Mail"
set newRepNotifyMessage to make new outgoing message with properties {subject:repNotifySubject, content:repNotifyBody & return & return}
tell newRepNotifyMessage
set visible to true
set sender to theSender
make new recipient at end of to recipients with properties {address:repEmail}
activate
send newRepNotifyMessage
tell application "Finder"
activate
display dialog "All Done." buttons ["OK"] default button 1
end tell
end tell
end tell
end tell
end tell --> mail
else if (exists folder jobJacketNumber of folder "active" of disk "proofs") = true then
tell application "Finder"
activate
display dialog "The job jacket number you entered already exists in the proofing system." buttons "OK" default button 1 with icon caution
move document file "ad_proof_th.pdf" to trash
end tell
end if --> job jacket check
end tell --> tell block for job jacket check
--> end core script <--
end if --> first proof or revision
end if --> count documents
end tell
Model: Power Mac G5
Browser: Safari 419.3
Operating System: Mac OS X (10.4)