Setting a more aggressive trigger for some rules

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

Moderator: Mr_Noodle

Hi,

I have a rule that mounts my NAS folders if the NAS is available (using Applescript to ping it and mount it). I have it running on the /Volumes folder and for the most part it works well... except that occasionally the drives aren't mounted even though I'm on my home network.

In some cases, I imagine this could be because of a race condition with the network coming online, maybe the rule is running before the NAS is pingable.

But then I realized that if I sue my laptop outside the house, then on returning, there won't be any change in /Volumes -- the disappearance of the network drives happened while I was out.

So, in order of (my) preference:

1) Hazel could have specific support for /Volumes, understanding that network changes, sleep/wake, etc are all triggers for rules on this folder.

2) Hazel could offer some other brute-force mechanism: run rules on a timer, for example.

3) I could make my current rule have some side-effect when the NAS isn't available (e.g. touch a file somewhere), which I can then use to trigger a re-try later. This sounds hard to do, and at best would be a gross hack. But maybe I'll give it a shot.

Thoughts? Other ideas? I'm very new to Hazel, so if I'm missing something basic, I'll be happy to learn the right way to do this :)
vthunder
 
Posts: 4
Joined: Sat Jun 14, 2014 6:11 pm

1. What specific event are you looking for here that Hazel isn't picking up? While I can see that Hazel won't automatically mount stuff, I'm not sure what other special support is needed.

2. If you really want to do this, you can try a condition like "Date last matched is not in the last 5 minutes". That said, for network drives, once mounted, Hazel does run on a timer because such volumes do not produce file events.

3. Hazel does automatically retry the rules when you mount the drive.

I guess if you can provide more specific situations where you see Hazel not doing what you need here, I can better assist.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Thanks!

Sorry I wasn't clear. The rule is to mount the drives only, not to do anything with the contents. It uses shell scripts to determine whether the mount is required, here's the full rule, on the /Volumes folder:

Condition 1, shell script:
Code: Select all
if [ -d "/Volumes/Documents" ]; then exit 1; else exit 0; fi


Condition 2, shell script:
Code: Select all
ping -o -c 1 -W 0.25 -n 10.0.1.5 2>&1 1>/dev/null


Action, applescript:
Code: Select all
tell application "Finder"
   try
      mount volume "afp://10.0.1.5/Documents"
   end try
end tell


This rule works OK, it generally keeps the drive mounted if I'm at home.

Assuming that Hazel will attempt to match the rule when it detects some change in /Volumes, then I am guessing that the problem scenario is something like:

1) I go to a coffee shop and open my laptop.
2) Network drive goes offline.
3) Hazel detects the change in /Volumes and runs the rule.
4) Rule determines the NAS is not available.

So far so good, but then I return home and open my laptop. And the rules don't run, because there is no trigger to make them run (/Volumes has not changed since last time the rules ran).

Does that make more sense?

Thanks!
Dan
vthunder
 
Posts: 4
Joined: Sat Jun 14, 2014 6:11 pm

When you come home and mount the drive, Hazel should trigger then. Or is the drive somehow not unmounted at any point?
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Mr_Noodle wrote:When you come home and mount the drive, Hazel should trigger then. Or is the drive somehow not unmounted at any point?


The point of the rule is to mount the drive. To monitor /Volumes, and keep the drive mounted whenever possible.

So, "When I come home and mount the drive" is what I want Hazel to do. Currently I do it via menu > Run Rules > Volumes, but I would like it to be automatic.
vthunder
 
Posts: 4
Joined: Sat Jun 14, 2014 6:11 pm

Well, Hazel isn't really intended to do actions based on arbitrary events. If you want something to mount, you'll need to use some other software that detects it and triggers. I think maybe Sidekick is what you are looking for.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

That's very unfortunate, did I throw away $30? I thought I could get Hazel to do this for me :-(
vthunder
 
Posts: 4
Joined: Sat Jun 14, 2014 6:11 pm

I guess I'm still not clear on what you are trying to do here. What exact cue is happening that you expect Hazel to pick up so that it will respond?
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support