Detect whether clipboard item is image data using AppleScript This started because I wanted to be able to paste screenshots or pictures copied from Safari into Finder folders. Here are the steps to get to where I am:

Install pngpaste using brew install pngpaste.

Make Automator Quick Action, and configure as:



osascript -e 'set formattedDate to (do shell script &quot;date +'%Y-%m-%dat%H-%M-%S%p'&quot;)' -e 'tell application &quot;Finder&quot; to set thePath to the quoted form of (POSIX path of (insertion location as alias) &amp; formattedDate &amp; &quot;.png&quot;)' -e 'if ((clipboard info) as string) contains TIFF picture then do shell script &quot;/usr/local/bin/pngpaste &quot; &amp; thePath' -e 'if ((clipboard info) as string) does not contain TIFF picture then tell application &quot;System Events&quot; to keystroke &quot;v&quot; using control down'


Save and close.
Remap default paste:



Assign default paste to trigger service:


THE ISSUE: No matter what type of file I have in my clipboard, the script always detects it as a TIFF and pastes it as a PNG. How do I fix this?
Having to write and maintain an osascript command as you have is really not the best way to go in this use case IMO.
Using a Run AppleScript action, instead of a Run Shell Script action, the following example AppleScript code will resolve the issue you are currently having, and makes the code much easier to read and edit:
on run {input, parameters}
    
    set cbInfoAsString to (clipboard info) as string
    
    if cbInfoAsString does not contain &quot;«class furl»&quot; and ¬
        cbInfoAsString contains &quot;TIFF picture&quot; then
        
        set formattedDate to do shell script ¬
            &quot;date -j '+%Y-%m-%d at %I.%M.%S %p'&quot;
        
        tell application &quot;Finder&quot; to set thePath to ¬
            (insertion location as alias) &amp; ¬
            formattedDate &amp; &quot;.png&quot; as string
        
        do shell script &quot;/usr/local/bin/pngpaste &quot; &amp; ¬
            the quoted form of the POSIX path of thePath
        
    else if cbInfoAsString contains &quot;«class furl»&quot; then
        
        tell application &quot;System Events&quot; to ¬
            keystroke &quot;v&quot; using control down
        
    end if
    
end run

Notes:

POSIX path is a part of Standard Additions not Finder, and should not be wrapped within a tell statement of Finder.
If not setting the date with the date command, use the -j option.
I modified your date command to use 12-Hour Time as typically 24-Hour Time does not use AM/PM and have added made additional modifications to make it more readable, and in line with the system default used with screen shots.
If you want  24-Hour Time then use e.g.: &quot;date -j '+%Y-%m-%d at %H.%M.%S'&quot;
As coded, if there is anything other than a file(s)/folder(s) or just an image, the script will not attempt to process text if that's what's on the clipboard.