Page 1 of 1

Read Spotlight Comments and write to Openmeta Tags

PostPosted: Thu Dec 06, 2012 10:11 am
by jamest
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

Re: Read Spotlight Comments and write to Openmeta Tags

PostPosted: Thu Dec 06, 2012 3:45 pm
by Mr_Noodle
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.

Re: Read Spotlight Comments and write to Openmeta Tags

PostPosted: Fri Dec 07, 2012 5:49 am
by jamest
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

Re: Read Spotlight Comments and write to Openmeta Tags

PostPosted: Mon Dec 10, 2012 3:21 pm
by Mr_Noodle
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.

Re: Read Spotlight Comments and write to Openmeta Tags

PostPosted: Mon Apr 22, 2013 6:25 am
by Cassady
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!!