Page 1 of 1

Trying to copy the comments of a file to macOS Finder tags

PostPosted: Tue Sep 29, 2020 6:33 am
by oyka
Hello,

I currently trying to sync my macOS Finder tags with the comments field of specific files with hazel.
Syncing tags to comments is pretty easy with the "add comment" command in hazel.
The other way around is not as easy. I am trying to workaround this with apple script, but I can't solve the error. I am using the command line tool tag in order to add tags to theFile (https://github.com/jdberry/tag)

Code: Select all
set the TheComment to the comment of theFile
do shell script "tag -a " & TheComment & " " & theFile


Does anyone know what I am doing wrong or does anybody have an alternative solution?
Best

Re: Trying to copy the comments of a file to macOS Finder ta

PostPosted: Tue Sep 29, 2020 9:58 am
by Mr_Noodle
What is the error you are seeing in the logs?

Re: Trying to copy the comments of a file to macOS Finder ta

PostPosted: Thu Oct 01, 2020 10:45 am
by oyka
The problem was the apple script syntax. Terminal is expecting the quoted form of a path in order to work with it.
I solved syncing comments to tags with this script:

Code: Select all
tell application "Finder"
   set the TheComment to the comment of theFile
   set ThePath to quoted form of the POSIX path of theFile
   set theScript to "/usr/local/Cellar/tag/0.10_1/bin/tag -a " & "'" & TheComment & "'" & " " & ThePath & ";exit;"
   do shell script (theScript)
   set theName to the name of theFile
   display notification theName with title "tags added"
end tell


Another question: as you can see I try to output a notification. When I run the script within macOS' script editor it just works. If I trigger the script with Hazel the notifaction is not shown. Is there a workaround?

Re: Trying to copy the comments of a file to macOS Finder ta

PostPosted: Fri Oct 02, 2020 10:28 am
by Mr_Noodle
There may be an issue with the Notification preferences. Maybe check those as well as your privacy settings?