Page 1 of 1

Applescript lookup table

PostPosted: Thu Jan 23, 2014 2:21 pm
by samberlu
Hi, I'm new to Hazel and am looking for some sorting advice.

I have filenames of which part should be used to move it to a folder.
Problem is the filename and the foldername are only partially similar.

Example. File "Sprint p00458 layout.txt" needs to be moved into a subfolder of "557482 Sprint".
From what I've been told this requires either separate rules for each instance (insane amount of work, to many folders, to often new ones). Or applescript.

Now, I know very little about applescript. What I think I need is a basic lookup table. Should be bale to do that with property lists. Put the token from Hazel into applescript to get the folder name back and put that back into hazel as the folder name.

Anyone that can help me with this?

Thanks.

Re: Applescript lookup table

PostPosted: Thu Jan 23, 2014 9:08 pm
by a_freyer
Look into shell script, specficially defaults read & write.

e.g.:

Code: Select all
 set myFolder to do shell script "defaults read com.myname.hazelscripting " & quoted form of theFileNamePart & "

Re: Applescript lookup table

PostPosted: Sat Jan 25, 2014 7:23 am
by samberlu
Thanks for the suggestion although I have no clue how that would work, isn't com.myname.hazelscripting the preference file?

Anyway I've resorted to stripping the path and the back end of the filename from the Hazel passed string and a giant perl substitution string to match all the cases, because sed for mac doesn't support case insensitive matching. And passing that back to Hazel.

It's far from ideal but it works just fine.