Problem with file paths.

Hello all. I am using this script in my automator action. When I run it I can get the selected finder items and open them as the next action, but ultimately what I want to do is be able to copy them, add spotlight comments, etc. As of right now if I try and do either the first step of getting the finder items works fine, but the output is apparently wrong because the next action, such as “Add Spotlight Comments” fails stating it was expecting a reference. If I try and change the output to the path as text my action fails stating it cant change my file into type reference. Can anybody help me out?

Here is what I have for the script:


on run {input, parameters}
	tell application "InDesign CS"
		set theSelection to item 1 of the selection
		set theClass to class of theSelection
		if theClass is in {EPS, PDF} then -- if the image is selected by direct tools 
			set theSelection to parent of theSelection
			set theClass to class of theSelection
		end if
		-- try to get the file path of the item: 
		set theFilePathOfImage to file path of item link of all graphics of theSelection
		
	end tell
	
	
	set output to theFilePathOfImage
	return output
	
	
	
end run

What I get in the end if run through Script Editor is this:

file "Work HD (Punkin):(2) Books In Progress:Columbiana Draft 1.indb Folder:Links:541.psd"

That is the name of the image that is linked through InDesign. If anyone could help that would be great!

Model: PowerMac G4
Browser: Safari 412
Operating System: Mac OS X (10.4)

Is some additional coersion needed? What is the class of the returned variable?

What do you mean what is the class of the returned variable? I am still unable to solve this problem.

Still clueless and need some help.

Your conditional statement

set theClass to class of theSelection
if theClass is in {EPS, PDF} then

will never be met becase EPS and PDF are not classes. They are file types. Classes are an item’s value type: disk, window, list, folder, document file.

Since the conditional is always false,


set theFilePathOfImage to file path of item link of all graphics of theSelection
--script lines
   set output to theFilePathOfImage
   return output

gets executed, where you set output to the file path of the image and told it to return this value, yielding

file “Work HD (Punkin):(2) Books In Progress:Columbiana Draft 1.indb Folder:Links:541.psd”

Let’s start over:



-- {"EPS ", "PDF "} These are four character items; notice the blank space

tell application "Finder"
	set theSelection to selection--Let the Finder do the selecting
end tell
repeat with thisItem in theSelection--Get each item, one at a time
	
	set FileType to (file type of thisItem) as string
	if FileType is in {"EPS ", "PDF "} then
		
		display dialog "The file:" & return & thisItem & return & "*of type '" & FileType & "'" & return & "has been accepted for processing." --remove this line after you see it run once
		
		set SLComments to display dialog "Log Spotlight Comments:" default answer ""
		set SLComments to text returned of SLComments as string
		--I don't have spotlight, but here is where you tell whichever app to set the Spotlight comments to SLComments
		
		--Add other actions here, but copy last so all changes made go with new copies
		
		set NewLocation to choose folder --Example of how to then copy file to location
		tell application "Finder"
			copy file (thisItem as string) to folder NewLocation --Does not replace same name items; Careful not to over write files!!!
		end tell
	end if
end repeat

If you wanted to move all files of the selection to the same place, that will take a little more tweaking. Play with this until you know what you need,
SC

“Otto is fine for a snack, but Applescript will keep your belly full”

I dont think you understand. I see the changes you made and will update my script, but this needs to be run from within indesign. The links within in-design are why I am writing this script. Of course it would be easy to go ahead and select the files with finder and then just add the comments, the thing is that the selection needs to come from within InDesign.

I could not find a reference to the purpose of indesign in your post. All of the things you are doing are Finder or system event jobs whose variables can be passed to indesign. Maybe you should restate the overall goal of your workflow.
SC

The goal is that while in InDesign it has a list of links, or files which are in the document. These files are located all over the computer and between multiple drives sometimes. I would like to, through InDesign, select the links from their centralized location (which is the links palette in InDesign) and add spotlight comments to the files of those links, for example “Whatever Book: Chapter 2” so that that link is able to be found via spotlight no matter its location, and we don’t need to leave InDesign and go searching just to add some comments to some files.

Even more important is if the files are centralized on the system I still would have to know all the filenames for the ones in a specific chapter and manually select them to add the comments, where as through InDesign I can select those links with one click and then could add the comments.