Removing the existing extension before saving with a new extension

Hello all. I’m trying to export Indesign files and save them as a pdfs, without the extension “.indd” showing in the name. Can anyone help?

set the_container to choose folder
tell application “Finder”
try
set fileNameList to (every file in entire contents of the_container whose name ends with “.indd”) as alias list
on error
set fileNameList to (every file in entire contents of the_container whose name ends with “.indd”) as alias as list
end try

tell application "Adobe InDesign CS3"
	activate
	tell application "Adobe InDesign CS3"
		repeat with iFile from 1 to count fileNameList
			set thisFilePath to item iFile of fileNameList
			set thisFilePath to thisFilePath as string
			set folder_path to (choose folder with prompt "Select folder to Save PDF files") as string
			open thisFilePath
			
			set myDocument to document 1
			set myName to name of myDocument
			set MyPDF to folder_path & myName & ".pdf"
			export document 1 format PDF type to (folder_path & myName & ".pdf") using PDF export preset "[Smallest File Size]" without showing options
		end repeat
	end tell
end tell

end tell

I have been using this inside the tell InDesign tell block:

set AppleScript's text item delimiters to {"."}
set fileBase to first text item of ((get name of active document) as string)
set AppleScript's text item delimiters to {""}

This assumes you are not using periods in your filename other than for the extension. If you are concerned about that, I have used this before. This would most likely go before your InDesign tell block. I’m copying this as is - I didn’t match your file names and, possibly, where I am referring to a path you might have an alias, etc. But hopefully this will get you started.

tell application "System Events" to set TheExtension to name extension of (this_item as alias)
if TheExtension is not "" then
tell (info for (this_item as alias)) to set FileName to name's text 1 thru ((my (offset of ("." & name extension) in name)) - 1)
else
tell (info for (this_item as alias)) to set FileName to name
end if

Matt,

A small change to your get statement will make it work for any amount of periods in the file name as long as there is an extension:

set OldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"."}
tell application "Adobe InDesign CS3"
	set fileBase to (text items 1 through -2 of (get name of active document)) as string
end tell
set AppleScript's text item delimiters to OldDelim
return fileBase

This converts the old file name into a list of text between the periods. The -2 tells the script to just get up to, but not including the last text item. Then the as string converts it back to a string, putting the periods in between the text items.

as all files end with indd, the easiest way is to replace


.
 set myDocument to document 1
 set myName to name of myDocument
 set MyPDF to folder_path & myName & ".pdf"
.

with


.
set MyPDF to folder_path & text 1 thru - 6 of (get name of document 1) & ".pdf"
.

Thank you everyone for help!!