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

Talk, speculate, discuss, pontificate. As long as it pertains to Hazel.

Moderators: Mr_Noodle, Moderators

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
oyka
 
Posts: 2
Joined: Tue Oct 08, 2019 12:32 pm

What is the error you are seeing in the logs?
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

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?
oyka
 
Posts: 2
Joined: Tue Oct 08, 2019 12:32 pm

There may be an issue with the Notification preferences. Maybe check those as well as your privacy settings?
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Open Discussion