I am placing the name of a document in a text editbox, Is there an easy way to eliminate the extension? I know in JS you can just type in…
var myDocumentName = stripExt(myDocument.name);
Is there something similar in AS?
set myDocument to active document
set myDocumentName to name of myDocument
set myDialog to make dialog
tell myDialog
tell (make dialog column)
set myBorderPanel to make border panel
tell myBorderPanel
make static text with properties {static label:"Name:"}
set myBaseNameField to make text editbox with properties {edit contents:myDocumentName, min width:180}
end tell
I came upon some code but I can’t quite get it to work can someone lend me a hand? For me the script errors out on the sub-routine.
--Remove Extension
tell application "InDesign CS"
set myDocument to active document
set myDocumentName to (name of myDocument) as string
display dialog "The name of the file is: " & ¬
return & return & myDocumentName buttons {"OK"} default button 1
set myDocumentName to remove_extension(myDocumentName)
display dialog "The name of the file without the extension is: " & ¬
return & return & myDocumentName buttons {"OK"} default button 1
end tell
on remove_extension(this_name)
if this_name contains "." then
set this_name to ¬
(the reverse of every character of this_name) as string
set x to the offset of "." in this_name
set this_name to (characters (x + 1) thru -1 of this_name) as string
set this_name to (the reverse of every character of this_name) as string
end if
return this_name
end remove_extension
on remove_extension(this_name)
if this_name contains "." then
set delim to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."
set cleanName to (text items 1 through -2 of (this_name as string) as list) as string
set AppleScript's text item delimiters to delim
return cleanName
else
return this_name
end if
end remove_extension