Trying to extract name of file from file link

Thank you in advance for all your help and advice…

why is generating and error when trying to get just the name of the file?

set buttonPressed to button returned of (display dialog “A Indesign document must be open and active” buttons {“Cancel”, “Document is open”, “Open document”} default button 3 with icon note with title “Process”)

set activeDocument to (choose file with prompt “Choose Indesign file to open and process” without invisibles) as string

display dialog activeDocument

display dialog name of activeDocument

Two things…

If you type three back ticks (the key above the tab and beside the 1) on the line above and the line below your code, it will be formatted correctly and easy for people to use. For example:

```
applescript code here
```

As to the question… it is because your second set command is coercing the file reference to a string. A string doesn’t have a name property at all.

Here are three ways to to get the name of the file.

use scripting additions
set buttonPressed to button returned of (display dialog "An InDesign document must be open and active" buttons {"Cancel", "Document is open", "Open document"} default button 3 with icon note with title "Process")
set activeDocument to (choose file with prompt "Choose Indesign file to open and process" without invisibles) -- as string

display dialog activeDocument as text with title "path to document"


tell application "Finder" to set nameDocF to (get name of activeDocument)
display dialog nameDocF with title "Name of document (finder)"

tell application "System Events" to set nameDocSE to name of activeDocument
display dialog nameDocSE with title "Name of document (system events)"

set nameDocIF to name of (info for activeDocument)
display dialog nameDocIF with title "Name of document (info for)"

Note that if you open the file in an application (such as InDesign) you can typically get the open document’s name at that point. Depending upon your objectives, that might be an approach to take.

2 Likes

name is an property from an application. Try this:

tell application "Finder" to set docName to name of activeDocument
display dialog docName

Try this:

tell application id "com.adobe.InDesign"
	activate
	
	if not (exists active document) then
		set theFile to choose file with prompt "Choose an Indesign file" of type {"com.adobe.indesign-markup", "com.adobe.indesign-document", "com.adobe.indesign-template"}
		if theFile = false then return
		open theFile as «class furl»
	end if
	
	set theName to name of active document
	display dialog theName with title "Document Name" buttons "OK" default button 1
	
end tell
1 Like