Action Failure by "Get Comment to Variable" (Get File Attribute Action)

I get an "Action Failed" message, when i try to get comments from a file. I tried it with different file types (files and folders, with comments and without comments).

It would be helpful if you post your (complete) macro.

If you don’t know how to post macros, you find the appropriate information in the [KM Wiki] (https://wiki.keyboardmaestro.com/Forum?s[]=posting)

Looks like you have uploaded a "TIFF" image of your macro, which does not display well. Please upload either a ".png" or ".jpg" format.

Of course, the best approach is the one @Tom referred to:
See

1 Like

If you look in the Engine.log file (Help ➤ Open Logs Folder) it will tell you the exact error message you are getting, which would indicate the problem.

My initial guess would be that the Path variable is wrong in some ways, but there is not enough information to make much of a guess at this point.

Here is the error message “2017-02-16 08:10:20 Get File Attribute failed for path %Variable%Path% attribute Comment”. Thank you for help!

Here is my Macro:

“Add Book Infos to Files” Macro

[PQ] Add Book Infos to Files.kmmacros (13 KB)

Macro-Image

Click image to expand...

Thank you for help!

Thanks for posting your macro.

Often it is best to test a simple macro that uses the feature you are having trouble with.

Please try this test macro and let us know if it works for you:

MACRO:   Get File Comments Property in Finder Selection @TEST


VER: 1.0    2017-02-16 ~~~

DOWNLOAD:

Get File Comments Property in Finder Selection @TEST.kmmacros (3.1 KB)


Example Results


2 Likes

I get this message when a file does not have a comment.

Probably I’m missing the obvious, but that message should be irrelevant to you:

Your whole macro is aimed at files without comment. You have disabled “Failure Aborts Macro” in the Get Comment action. And then the whole rest of the macro only executes if the comment is empty (variable “aboutBook” is empty). The “otherwise” part of the “If then” does not contain anything.

So, I guess, the problem is not the non-existing comment, but some other thing further down the road.

But, as said, I may be missing the whole point of the macro. :wink:

1 Like

I know this is an old thread and I'm experiencing the same problem. The get comment to variable action throws a failure when there is no comment on the file being checked. This would abort the macro but I have "Failure Aborts Macro" unchecked.

TEST - File Comment.kmmacros (1.5 KB)

Here is what I see in the logs when I run it:

2022-09-15 19:32:35 Execute macro “TEST - File Comment” from trigger Editor
2022-09-15 19:32:35 Action 516679 failed: Get File Attribute failed for path ~/IMG_4660.MOV attribute Comment
2022-09-15 19:32:35 Get File Attribute failed for path ~/IMG_4660.MOV attribute Comment in macro “TEST - File Comment” (while executing Get Comment to Variable “instanceComment”).
2022-09-15 19:32:35 Log: Comment: 

If this is the intended behavior I can work around it. Otherwise, it seems like this isn't working correctly. I'm running KM 10.2

Have a look at this post by Howard Oakley to learn more about the... interesting implementation of Finder Comments.

I think it's unavoidable. A file/folder without a comment doesn't have an empty string in a "comment field" -- it has no "comment field" at all, so asking about it will return an error. You can see this in Terminal, first with a file that has a comment then one without:

nige_s$ xattr -p com.apple.metadata:kMDItemFinderComment nige_s001.tif;echo "Exit code: $?" 
62 70 6C 69 73 74 30 30 5E 49 20 61 6D 20 61 20
63 6F 6D 6D 65 6E 74 08 00 00 00 00 00 00 01 01
00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 17
Exit code: 0
nige_s$ xattr -p com.apple.metadata:kMDItemFinderComment nige_s002.tif;echo "Exit code: $?" 
xattr: nige_s002.tif: No such xattr: com.apple.metadata:kMDItemFinderComment
Exit code: 1

...where you can see that "no comment" means "no attribute" means an error is returned.

If you don't care about files/folders with no comments applied then do as you've done and uncheck "Failure Aborts...". If you do care, eg you'd like to list the path of every file without a comment, put your "Get comment..." in a "Try/Catch" block and handle the error in the "Catch" section.

3 Likes

That makes sense. Thank you. When I first used this action I had assumed that it would return an empty variable if no comment. At least there is a way to handle KM bubbling up the attribute missing error.

@Nige_S is on the money when you're working with Finder comments in Keyboard Maestro.

However – you can use AppleScript to do this instead, and it will return an empty string rather than throw an error for items that aren't commented.

--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2022/09/25 16:02
# dMod: 2022/09/25 16:02 
# Appl: Finder
# Task: Get the Finder Comment of the First Item Selected in the Finder.
#     : Returns an empty string "" if there are no comments.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Finder, @Comments, @Selected_Items
--------------------------------------------------------

tell application "Finder"
   set finderSelectionList to selection as alias list
   if length of finderSelectionList = 0 then error "No files were selected in the Finder!"
   set theItem to item 1 of finderSelectionList
   set itemComment to theItem's comment
end tell

--------------------------------------------------------

-Chris

1 Like