Read Spotlight Comments and write to Openmeta Tags

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Hello :)

I'm using hazel to write "tags" to spotlight comments based on the name of a file. Then this file is sorted into different subfolders based on creation date ( YYYY -> MM).

The problem is I would like to use a software like YEP, because I don't wan't to have so many different "custom searches" in the finder to find bills from a single company or a special date. So I needed a way to write these "tags" from the filename also to the openmeta tags. At the moment Hazel doesn't support custom fields in openmeta tags. (http://www.noodlesoft.com/forums/viewtopic.php?f=4&t=1847) So I couldn't set tags dynamically from the filename.

So I tried my first steps with applescript and here is the result:

Code: Select all
set openmeta to "/Applications/openmeta/openmeta"

tell application "Finder"
   set theFilename to (name of theFile) as string
   set theFilePath to (the POSIX path of theFile)
   set thisfile to (POSIX file theFilePath) as alias
   set theFileComment to the comment of thisfile
end tell

set {myTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {","}}
set myList to text items of theFileComment
set AppleScript's text item delimiters to myTID

repeat with myItem in myList
   set theTags to do shell script openmeta & " -a " & myItem & " -p " & quoted form of POSIX path of theFile
end repeat

return {hazelExportTokens:{filename:theFilename, comment:theFileComment}}


I think the code isn't perfect and maybe it could be much shorter, but at the moment it works. Could someone with some more applescript Knowledge please take a look at it and tell me if something isn't done as it should?

Thanks so much

Jamest
jamest
 
Posts: 9
Joined: Mon Nov 26, 2012 6:07 pm

One little thing I noticed: not sure if you need "thisfile". It's seems like an alias made out of the file path from theFile, which is already an alias. I'd say nix "thisfile" and just use "theFile" in its place.
Mr_Noodle
Site Admin
 
Posts: 11865
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Hello Paul,

thanks for the tipp, I could reduce the code a little bit. :)

Code: Select all
set openmeta to "/Applications/openmeta/openmeta"

tell application "Finder"
   set theFilename to (name of theFile) as string
   set theFilePath to (the POSIX path of theFile)
   set theFileComment to the comment of theFile
end tell

set {myTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {","}}
set myList to text items of theFileComment
set AppleScript's text item delimiters to myTID

repeat with myItem in myList
   set theTags to do shell script openmeta & " -a " & myItem & " -p " & quoted form of POSIX path of theFile
end repeat

return {hazelExportTokens:{filename:theFilename, comment:theFileComment}}


That works very well. :)

I just noticed one thing, sometimes hazel crashes if I'm in the script editor.

Jamest
jamest
 
Posts: 9
Joined: Mon Nov 26, 2012 6:07 pm

If the script editor is crashing, please send me the crash report. Go to your Library/Logs/DiagnosticReports folder and file the file(s) named with System Preferences and with a date that matches the time of the crash. Just click the "Contact Support" button in Hazel and attach it to the resulting Mail window.
Mr_Noodle
Site Admin
 
Posts: 11865
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Thanks for this!

I was planning on doing the same at some point in the future, but wasn't even sure if it was possible. I bought the entire Ironic Software package bundle, so wanted to get some use out of it... Then I purchased DEVONthink Pro, which basically replaced my need for Leap/Yep... But seeing this, I'm now re-considering...

Since DtP reads all metadata tags - I could easily (I hope) set Hazel up to do the legwork in tagging prior to importing the new files into DtP - so this is a very big help!!
Cassady
 
Posts: 47
Joined: Wed Mar 06, 2013 4:34 pm


Return to Support