The script below does what I need it to do… I just want it to do it better.
I run this script from within InDesign and want some minor tweaks for it.
- I want the final file name to not have the “.indd” extension… just “filename.pdf”
ALSO, if i have a series of Export to files and/or Print commands can I write a script that runs other applescripts?
-- have to use PRINT because PDFs are 50% of document size
tell application "InDesign CS"
activate
if (count documents) = 0 then
display dialog "Please, open a document" buttons " Ok " default button 1 with icon caution
return -128
end if
set docName to full name as Unicode text
set printFile to (docName & "_KMC.pdf") as string
print active document using " 5. KMC Web PDFs" with print dialog
--count 30
beep
display dialog "KMC Web PDF File Created." buttons {"OK"} default button 1 giving up after 2 with dialog
end tell
Here’s some sample code showing how to remove the extension:
tell application "Adobe InDesign CS2"
set docName to full name of document 1 as Unicode text
set docName to my removeExt(docName) & "_KMC.pdf" as string
end tell
on removeExt(thisItem)
set thisItem to thisItem as text
set myOffset to offset of "." in (reverse of characters in thisItem as text)
set newName to characters 1 thru -(myOffset + 1) of thisItem as text
return newName
end removeExt
Will they work independently of the loading script or would they work on files as directed by the loading script? Either way, yes, you can. You can read a little in the Standard Additions dictionary, search for ‘load script’ and ‘run script’.
Thanks for the advice…
I tried to integrate your idea into my previous script. Running your’s alone the “result” window in Applescript shows the right file name but when run as a whole (from Indesign CS) the final PDF is NOT renamed and saved to the desktop.
Any reason why it would be doing that? And I’d prefer to have the file created at the same location of the source
-- have to use PRINT because PDFs are 50% of document size
tell application "InDesign CS"
activate
if (count documents) = 0 then
display dialog "Please, open a document" buttons " Ok " default button 1 with icon caution
return -128
end if
set docName to full name of document 1 as Unicode text
set docName to my removeExt(docName) & "_KMC.pdf" as string
end tell
on removeExt(thisItem)
set thisItem to thisItem as text
set myOffset to offset of "." in (reverse of characters in thisItem as text)
set newName to characters 1 thru -(myOffset + 1) of thisItem as text
return newName
end removeExt
tell application "InDesign CS"
set printFile to docName
print active document using " 5. KMC Web PDFs" with print dialog
--count 30
beep
display dialog "KMC Web PDF File Created." buttons {"OK"} default button 1 giving up after 2 with dialog
end tell