Hi, there!
Recently, I met a problem that I don’t know why I can’t change pdf file metadata in DEVONthink. So I use some outside tools, such as Acrobat, to do some change, it worked, seems pdf file is fine, maybe it is DEVONthink’s problem, or other problem.
I write an Apple script to use exexiftool
to directly change selected pdf metadata in DEVONthink. Now, I want to share this script for all.
-- Change metadata of selected PDF files in DEVONthink
tell application id "com.devon-technologies.think3"
-- Get the currently selected items
set selectedItems to selection
if (count of selectedItems) = 0 then
display dialog "No files selected." buttons {"OK"} default button "OK"
return
end if
-- Provide a list of metadata fields for the user to choose from
set metadataOptions to {"Author", "Title", "Subject", "Keywords", "Organization", "Copyright"}
set metadataField to choose from list metadataOptions with prompt "Please select the metadata field to update:" default items "Author" with title "Select Metadata Field"
if metadataField is false then
display dialog "No metadata field selected." buttons {"OK"} default button "OK"
return
end if
set metadataField to item 1 of metadataField -- Get the selected field name
-- Prompt the user to input a new value for the selected metadata field
set newValue to text returned of (display dialog "Enter the new value:" default answer "")
if newValue is "" then
display dialog "The new value cannot be empty!" buttons {"OK"} default button "OK"
return
end if
-- Iterate through the selected items
repeat with theItem in selectedItems
set itemType to type of theItem
-- Process only PDF files
if itemType = PDF document then
try
-- Get the file path
set filePath to path of theItem
-- Use exiftool to modify PDF metadata
set exiftoolPath to "/opt/homebrew/bin/exiftool" -- Ensure this is the correct path to exiftool
do shell script exiftoolPath & " -" & metadataField & "=" & quoted form of newValue & " -overwrite_original " & quoted form of POSIX path of filePath
-- Notify the user of the successful update
display notification "Updated: " & name of theItem
on error errMsg
display dialog "Failed to modify: " & errMsg buttons {"OK"} default button "OK"
end try
else
display notification "Skipped non-PDF file: " & name of theItem
end if
end repeat
display dialog "All selected PDF files have been successfully updated!" buttons {"OK"} default button "OK"
end tell
Ps1:You need to install exiftool
. Use Homebrew to install: brew install exiftool
.
Ps2:You need to change exiftool
path as your local path.