extract xmp metadata from pdf file

I don’t understand your last post, do you want me to change the format of the outputPath?
I think I used the correct format for that, and I don’t use the open command.

Yes, you are using a POSIX path (/path/to/myFile.ext) but the open (for access) command needs a HFS path (DiskName:path:to:myFile.ext).
The POSIX path causes the file to be written into the root directory

I’ve set the Path to an HFS path

set hfsPath to POSIX file outputPath

Now I get another error when I try to write the file.

file can not be converted to type file specification.

I recommend to specify the destination directory at the beginning of the script. Try this


on open (theFiles) --acties bij gebruik als droplet
	extractXMP(theFiles)
end open

on run --acties bij gewoon gebruik
	set theFiles to (choose file with multiple selections allowed without invisibles)
	extractXMP(theFiles)
end run

on extractXMP(theFileList)
	repeat with theFile in theFileList
		
		--naam en pad opslaan
		set POSIXFilePath to POSIX path of theFile
		set theFileName to name of (info for theFile)
		set baseDir to POSIX file (do shell script "/usr/bin/dirname " & quoted form of POSIXFilePath) as text
		--exiftool commando opstellen en uitvoeren
		set mePathPOSIX to POSIX path of (path to me)
		set exiftoolPath to mePathPOSIX & "Contents/Resources/exiftool"
		set theShellCommand to quoted form of exiftoolPath & " -XMP -b" & space & quoted form of POSIXFilePath
		set theXMPcontents to do shell script theShellCommand
		
		if theXMPcontents is not equal to "" then
			set outputPath to baseDir & ":" & text 1 thru -4 of theFileName & "xmp"
			display dialog outputPath
			
			--xmp bestand schrijven
			set textFile to open for access file outputPath with write permission
			try
				set eof of textFile to 0
				write theXMPcontents to textFile
				close access textFile
			on error e
				close file outputPath
				display dialog e
			end try
			
		else
			display dialog "Er zit geen XMP file in " & theFileNameChopped
		end if
		
	end repeat
end extractXMP

Thanks! The script works perfectly now!