filename length checking?

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

Moderator: Mr_Noodle

filename length checking? Sun Jul 07, 2013 4:20 am • by QuaCKeReD
Hi All,

Wonder if anyone can help - have tried search and find nothing for this.

I have a MacMini that was running fine, although a little slow at times, until the 2013-003 security update, which I applied yesterday.

If all started during the updates required reboot;
The server froze and didn't come back after reboot. It had to be hard reset.
Then, within 5minutes of logging onto the server, the hazelworker process consumes as much physical RAM as it can, then starts on virtual, and kills the machine.
i.e., 4Gb machine, with other processes running, it quickly jumps to 1.5GB physical RAM (value of 'free' RAM beforehand).
I even got a popup dialog saying machine didn't have enough memory, please close applications (yes, I am definitely running OSX, not Windows) !!!

Stopping Hazel when it does this makes no difference, the process stays.

By process of elimination, I have this down to a single rule;
if kind is image AND dateadded is after lastmodified
rename with pattern <pixel width>x<pixel hight> - <name> (processed) <extension>

And, as rule preview showed a single file, a possible cause.
By testing I believe the issue was down to the filenames length, as shortening it allowed the rule to work fine (auto download from Flickr).

So, my question; is it possible, within Hazel, to check filename length and shorten it if it is over a certain length, or do I have to do this via a script?

Regards
Mark
QuaCKeReD
 
Posts: 8
Joined: Thu Nov 29, 2012 12:47 pm

Re: filename length checking? Mon Jul 08, 2013 11:00 am • by a_freyer
Good detective work. Initially, have you set a flag to avoid already-renamed files? I ask because I cannot confirm your situation on my machine.

If you would like to restrict string lengths, you can work within shell scripts:

Code: Select all
if (all) of the following conditions are met for (the file or folder being processed):
     embedded script
     …

Do the following to the matched file or folder:
     …


Code: Select all
#Extract the base filename without path
FilenameWithoutPath=$(basename "$1")

#Determine the length of the filename without path
LengthOfFilenameWithoutPath=$(echo ${#FileNameWithoutPath})

if [ $LengthOfFilenameWithoutPath -gt 20 ]; then
     #If length is greater than 20, then exit 1 to tell Hazel *not* to match
     exit 1
else
     #if length is less than of equal to 20, exit 0 to tell Hazel to match the file
     exit 0
fi

a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: filename length checking? Mon Jul 08, 2013 12:32 pm • by Mr_Noodle
I've respond to your email already but I thought I'd post here as well (in the future, post in one place or the other). Looking at the rule, it does appear that it will loop infinitely since it does not filter out files after they have been renamed. Adding a condition to detect that should stop it.
Mr_Noodle
Site Admin
 
Posts: 11865
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: filename length checking? Mon Jul 08, 2013 12:44 pm • by QuaCKeReD
Thanks for the feedback.

a_freyer - thanks for the answer to my Q, will add script to check length
Mr_Noodle - email was bug report, this post was question for temporary solution :D

However, the issue isnt with files being processed multiple times - the
Code: Select all
AND dateadded is after lastmodified

section resolves that (at least does for me).

The issue was if filename was already very long. Adding the extra field text to it seemed to cause the issue.

Proven by shortening the filename, and rule processed fine?

EDIT: Doh, typed out the code section wrong initially, no wonder you both thought that :)
Should have read, and is on rule;
Code: Select all
AND dateadded is after lastmatched
QuaCKeReD
 
Posts: 8
Joined: Thu Nov 29, 2012 12:47 pm


Return to Support