Save IDML file to same folder as original document

I’m trying to compose a script that will take the active document (in InDesign CC), grab its name, grab the file path of where it came from, and then export an IDML file to that same folder and with the same name. I keep getting stuck with telling applescript where to save the new IDML file.

I’m suspect that it’s not difficult, I just can’t figure out the correct syntax.

Thanks!
Tia

--Created 8/22/13 by Tia
--GOAL: open old indd file, save as idml, open that idml, then overwrite old indd with new indd (delete idml?)

tell application "Adobe InDesign CC"
	set myDoc to active document
	set oldName to name of myDoc
	--creating text only version of file name (excludes extension)
	set shortOldName to text 1 thru ((offset of ".indd" in oldName) - 1) of oldName
	set oldPath to the file path of myDoc
	
	tell myDoc
		export format InDesign markup to oldPath
	end tell
	
end tell

Model: iMac
AppleScript: 2.5.1
Browser: Safari 536.30.1
Operating System: Mac OS X (10.8)

Try this:

tell application id "com.adobe.InDesign" -- Adobe InDesign
	set myDoc to active document
	set oldName to name of myDoc
	--creating text only version of file name (excludes extension)
	set shortOldName to text 1 thru -6 of oldName
	set oldPath to the file path of myDoc
	set idmlPath to (oldPath as string) & shortOldName & ".idml"
	export myDoc format InDesign markup to file idmlPath
end tell

One minor edit to Shane’s:

Open this Scriplet in your Editor:
tell application id "com.adobe.InDesign" -- Adobe InDesign
   set myDoc to active document
   set oldName to name of myDoc
   --creating text only version of file name (excludes extension)
   set shortOldName to text 1 thru -6 of oldName
   set oldPath to the file path of myDoc
   set idmlPath to (oldPath as string) & shortOldName & ".idml"
   export myDoc format InDesign markup to file idmlPath
end tell

The last line needs to save to idmlPath not oldPath

Model: MacBook Pro 2.7 GHz Core i7 16GB RAM
Browser: Safari 537.31
Operating System: Mac OS X (10.8)

Thank you! I’ve edited it to correct the mistake.