Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

BenDeroo

macrumors newbie
Original poster
Jan 20, 2024
2
0
Couldn't find a direct answer, so here is my question:

A bunch of images have been marked by me with custom tags (architecture)
It is possible to select these images and have Sonoma generate a pdf (standard function)

I would like the tags (living room, bedroom) to show in the generated pdf as a description of some sort.

How would I go about doing this?

Thanks for any suggestions.
 

bogdanw

macrumors 603
Mar 10, 2009
6,144
3,042
First draft of an AppleScript that uses NConvert to convert images to pdf files with the tag name added to the file name

AppleScript:
tell application "Finder"
    set theImages to choose file with prompt "Please select the image files:" of type {"public.image"} with multiple selections allowed
    repeat with currentFile in theImages
        set theOutputFolder to POSIX path of ((container of currentFile) as text)
        set theImage to POSIX path of (currentFile as string)
        set extension hidden of currentFile to true
        set theName to displayed name of currentFile
        set extension hidden of currentFile to false
        set TagName to (do shell script "mdls -name kMDItemUserTags " & quoted form of theImage & "| sed -e 's/kMDItemUserTags = (//; s/)//' -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e '/^$/d'" as text)
        set thePDF to (theOutputFolder & theName & "_" & TagName & ".pdf" as text)
        do shell script "/Applications/NConvert/nconvert " & " -out pdf -o " & (quoted form of thePDF) & " " & (quoted form of theImage)
    end repeat
end tell

To install NConvert, download the latest NConvert from https://www.xnview.com/en/nconvert/
direct link https://download.xnview.com/NConvert-macosx64.tgz unarchive NConvert-macosx64.tgz into Applications and run from Terminal:
Code:
xattr -dr com.apple.quarantine /Applications/NConvert
 
  • Like
Reactions: BenDeroo

bogdanw

macrumors 603
Mar 10, 2009
6,144
3,042
Maybe someone knows how to turn the command mdls -name kMDItemUserTags into a variable in Shortcuts or Automator, so that you don’t have to use a third-party app to convert to pdf.
 

AlumaMac

macrumors 6502
Jan 25, 2018
394
744
Maybe someone knows how to turn the command mdls -name kMDItemUserTags into a variable in Shortcuts or Automator, so that you don’t have to use a third-party app to convert to pdf.

What about using the preinstalled 'sips' terminal command to convert images to pdf?
 
  • Like
Reactions: bogdanw

bogdanw

macrumors 603
Mar 10, 2009
6,144
3,042
What about using the preinstalled 'sips' terminal command to convert images to pdf?
Great idea! Although the sips manual doesn’t mention pdf, it can convert to pdf.
So the script can be:
AppleScript:
tell application "Finder"
    set theImages to choose file with prompt "Please select the image files:" of type {"public.image"} with multiple selections allowed
    repeat with currentFile in theImages
        set theOutputFolder to POSIX path of ((container of currentFile) as text)
        set theImage to POSIX path of (currentFile as string)
        set extension hidden of currentFile to true
        set theName to displayed name of currentFile
        set extension hidden of currentFile to false
        set TagName to (do shell script "mdls -name kMDItemUserTags " & quoted form of theImage & "| sed -e 's/kMDItemUserTags = (//; s/)//' -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e '/^$/d'" as text)
        set thePDF to (theOutputFolder & theName & "_" & TagName & ".pdf" as text)
        do shell script "sips -s format pdf " & (quoted form of theImage) & " -o " & (quoted form of thePDF)
        end repeat
end tell
 
  • Like
Reactions: AlumaMac
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.