You can find all keywords assigned to any photo, if you irate about all media items in the library.
This snippet of code will collect a list of all used keywords:
tell application "Photos"
set usedKeys to {" "}
set theItems to its media item as list
repeat with im in theItems
tell im
set kws to its keywords as list
if (exists kws) and kws is not {missing value} then
set usedKeys to kws & usedKeys
end if
end tell
end repeat
end tell
return usedKeys
To make it more convenient you could sort this list alphabetically and weed out duplicates.
But there seems to be no way to have AppleScript show all keywords stored in the library, including unused keywords.
The list of keywords from the keyword Manager cannot be copied to a textfile, as I had hoped.
I found a simpler work-around, without scripting.
You can simply select the Photos view in Photos and select all photos at once with ⌘A.
Then open the Keyword Manager.
All used keywords will be highlighted in blue, the unused keywords are white. Take a screenshot.
Then you can use the "Edit keywords" command to delete the unused keywords. For example - I selected all photos in the library. All keywords in blue are used by some photos, the others are not in use.