Run rule on file count to stop all hazel

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

Moderator: Mr_Noodle

Run rule on file count to stop all hazel Tue Feb 16, 2016 1:35 pm • by elpachato
Hello,

Firstly, sorry if my english can be strange or difficult to understand, since i am french, thanks for your understanding.

So, i am using Hazel in an automated workflow, in which my macbook is receiving pictures wirelessly from multiple cameras and smartphones for automated watermarked and reframed printing.

In this setup i use hazel for lauching the automator workflows that launches the photoshop dropplets.

Since i had multiple photoshop dropplets to run alternatively, i needed each photoshop dropplet to be run at once, because if not, it might eventually "miss" some pictures.

I have successfully created a sort of hierarchy in hazel, with multiple folders running rules based on applescripts that delays each launching of automator action until none is running, i have managed to do that for 5 folders/sources.

I don't know if i did it the best way, maybe not, but for the conditions i required it works fine and also does a kind of a loop between all folders. However it won't work for more than 5 folders, maybe in the future i will try to improve it, so if by the way you have any idea for this, let me know.


So for now, what i really need to do is to limit the total amount of prints.

Until now, i was running only one printer and limiting by the size of the paper roll, but for speed issues, i am now running it on a pool of 2 printers, and maybe i will add one more.

So i can't continue to rely on paper roll size for limiting the amount of prints, it is too much.

What i have tried, is to do a monitoring of the file count in the folder where all printed files are gathered, and tell hazel to stop (same as done manually i the hazel menu) when the indicated amount is reached , this would be perfect way as it would not only stops all folders watchers and launchers, but also the automator action that is already running, and then it would make a perfect count.

For now i have tried to simply run an automator action that stays up until user action, it should do the same trick except it would let the automator action continue and maybe allow for several more prints (each launcher runs 5 files per loop).

I say "it would" because i could'nt get even the file count working right in hazel, maybe it's a bug ?

If anyone can help me get a way to stop all hazel when file count is reached in selected folder that would be great.

Thanks in advance.
elpachato
 
Posts: 11
Joined: Tue Feb 16, 2016 12:47 pm

You can't really stop Hazel like that in an automated way. You'll need to structure your rules instead to not match things after a certain point. I can't quite wrap my head around your whole workflow but you'll have to look into ways of limiting things using the rule logic.
Mr_Noodle
Site Admin
 
Posts: 11875
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Thanks for your reply

So being logical, i just tried to stop hazel by killing process :

- killing hazelhelper : closes hazel in the top bar and stops all watchers and launchers
- killing hazelworker : stops all running "workers" (in my case automator action and other pending actions waiting via applescript for the one running to finish)

I suppose telling the system to kill those by applescript should not be a problem, even if the script is launched by hazel itself ?

To relaunch hazel, just went back to "préférences système" (don't how it is called in english) and clicked on hazel, all went back running normal.

Maybe the issue could be if hazel can relaunch itself, i have tried waiting for 20min, it didn't happen, opening "préférences système" whithout clicking hazel didn't relaunch either.

It is not a problem for me to relaunch only manually, because it is exactly what i am looking for, to be in control when the file count is reached.

It would have been great to just stop it but killing is ok for me i have not any other use at the same time.



Then i still have the issue about file count, how does it works ?

I have tried :
any is met / "sub-file/folder count" "is greater than" "10" => nothing
none is met / "sub-file/folder count" "is less than" "10" => nothing

I also tried in menu other "nombre d'éléments" which is french for "file count", does nothing either..

I don't get why, bug ?

Should i do it into applescript too ?
elpachato
 
Posts: 11
Joined: Tue Feb 16, 2016 12:47 pm

here is the script working to close all hazel

Code: Select all
tell application "System Events"
   set ProcessList to name of every process
   if "HazelHelper" is in ProcessList then
      set ThePID to unix id of process "HazelHelper"
      do shell script "kill -KILL " & ThePID
   end if
   repeat
      set ProcessList to name of every process
      if "HazelWorker" is in ProcessList then
         set ThePID to unix id of process "hazelworker"
         do shell script "kill -KILL " & ThePID
      else
         exit repeat
      end if
   end repeat
end tell


Works fine if i put in condition "any file", but not with file count condition, it never matches.

I am trying to script the "file count" without succes, i keep getting errors
elpachato
 
Posts: 11
Joined: Tue Feb 16, 2016 12:47 pm

I would not kill the HazelHelper process. In general, killing the processes is not a safe way to do things. For subitem count, is the rule matching a folder within the folder being monitored by Hazel? Note that rules pertain to the items inside the monitored folder, and not the folder itself. If you want to have a rule apply to the monitored folder, then you will need to monitor the folder that contains it, and then have the rule match that folder.
Mr_Noodle
Site Admin
 
Posts: 11875
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

I understand that this may not be the best way, but for my setup i can't find better for now.

The problem in my setup is that since i have 5 folders monitored that launches each at a time an action that passes 5 images, the only way to achieve all the processes without errors and being able to verify the state of it, is that each of the processed images is moved to the one final folder prior its opening in photoshop, this is the folder i need to monitor to achieve the count of prints, but since this folder doesn't launch anything itself, i can't see any other way to make it other then by this kill action.

If there was a way not to kill but just stop, just as when i click on the menu, it would be better for sure, but anyway, if hazel happened to crash during the whole process, i would not loose any data because everything is externalized, hazel acting here only as a launcher, i don't think it there is any risk at all.

In fact, when i click manually on stop hazel, it seems to do the same trick with automator actions, i guess, and it doesn't prevent anything from working right again..

For monitoring the folder i have finally made it with an other applescript

Code: Select all
tell application "Finder"
   set numberOfFiles to count of (paragraphs of (do shell script "mdfind -onlyin " & quoted form of "POSIX path of theFolder" & " kMDItemFSInvisible == 0"))
   if numberOfFiles > numberofprintswanted-1 then
      return true
   else
      return false
   end if
end tell


I have not really understood how works the folder sub-file count in hazel, but with that script for condition it does stop everything right away when the last wanted print is launched.

Now i can improve the alternating of the launching of the 5 initial folders monitored (that i would like to be 6), i will try to explain my setup later.

Thanks a lot
elpachato
 
Posts: 11
Joined: Tue Feb 16, 2016 12:47 pm


Return to Support

cron