Activate Hazel rule through AppleScript

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

Moderator: Mr_Noodle

Activate Hazel rule through AppleScript Thu Jan 25, 2018 5:11 pm • by Redwish
I use Hazel to watch folders and open them in Subtitler automatically.

Now I'm trying to set up triggers on my iPhone through Launch Center Pro and Keyboard Maestro. I've already set up the Keyboard Maestro trigger (web server) to activate the action but I would like to know how to activate an AppleScript through Keyboard Maestro and trigger a new Hazel rule to watch the folder.

Example: Specific media comes in when it's available. Hazel triggers a rule to add the media to Subtitler and scan automatically for the best fitting subtitle. When the subtitle isn't available it doesn't add it to my folder and Hazel ignores the file the next time, since it's already being scanned. When I want to check later I want a trigger in Launch Control Pro on my iPhone and let Hazel run a rule to scan all media added in the past 6 hours/last day.

I already use Keyboard Maestro to trigger some other rules and would like to keep it within Keyboard Maestro. (I know another method through Draft and Dropbox but do not prefer this).

Is there anyone which can help me with a AppleScript to trigger a specific/single rule within Hazel?
Redwish
 
Posts: 4
Joined: Thu Jan 25, 2018 4:54 pm

Re: Activate Hazel rule through AppleScript Fri Jan 26, 2018 11:23 am • by Mr_Noodle
I'm not entirely clear on why you need to trigger anything but instead of focusing on triggering Hazel to do anything directly, try manipulating something in the files that Hazel will see as a change and act on accordingly. For instance, you can set a tag on a file.
Mr_Noodle
Site Admin
 
Posts: 11240
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Activate Hazel rule through AppleScript Fri Jan 26, 2018 11:38 am • by Redwish
Thanks for the quick reply!

The reason I want to trigger a rule is that I want to force an app remotely to perform some action.

Working example: I have a trigger in Launch Control Pro to force my Plex Media Server to update my library.
Workflow: Launch Control Pro > Keyboard Maestro (Web Server) > AppleScript > Plex Media Server.

What I want to create is a forced commando from my iPhone to activate a Hazel rule.
Workflow: Launch Control Pro > Keyboard Maestro (Web Server) > AppleScript > Hazel (Rule: Scan last added items from last 6 hours) > Subtitler

The situation now is that Hazel scans my incoming media and is adding them to Subtitler (To auto scan and add the right .srt to the files). When Subtitler hasn't found a fitting subtitle it stops searching and does nothing. Hazel also doesn't try to add this file again to Subtitler since it's already scanned once.

When I come home from work in the evening and want to watch the media, sometimes i see that Subtitler hasn't found subtitles. This is because when the media was received on my Mac (Mostly in the morning) the subtitle wasn't available yet, but most of the time it is on a later time that day (When I come home from work).

Now I have to go to my Mac and manually add the files to Subtitler. To get rid of this and be lazy-as-something I want to manually trigger a semi-automatic process to scan my files again in the evening.
Redwish
 
Posts: 4
Joined: Thu Jan 25, 2018 4:54 pm

Re: Activate Hazel rule through AppleScript Fri Jan 26, 2018 1:05 pm • by Mr_Noodle
In that case, it might be better to have Hazel detect when the subtitle file is present.

For instance, you can use the conditions below to detect if a corresponding srt file is present:
Code: Select all
If (all) are met
    Name matches (• video file name)
    If (all) are met for (any file or folder in the same folder)
        Extension is srt
        Name matches (• video file name)

(• video file name) would be set to match "anything". Read the help on match patterns and nested conditions if you don't understand the above.

So what this does is match a file if another file with the same name, but srt extension exists in the folder. Doing it this way makes it automatic with no need to manually trigger anything.
Mr_Noodle
Site Admin
 
Posts: 11240
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Activate Hazel rule through AppleScript Fri Jan 26, 2018 3:57 pm • by Redwish
Awesome, hero of the day!

This way it’s even better. I’m gonna try this later on this day, will post the outcome.
Redwish
 
Posts: 4
Joined: Thu Jan 25, 2018 4:54 pm

Re: Activate Hazel rule through AppleScript Fri Jan 26, 2018 9:41 pm • by Redwish
2 rules created to watch my Downloads-folder:

Image

Image
Redwish
 
Posts: 4
Joined: Thu Jan 25, 2018 4:54 pm

Re: Activate Hazel rule through AppleScript Mon Jan 29, 2018 9:39 am • by Mr_Noodle
The second rule doesn't look right. Compare it to the example I posted. You want to use a custom attribute and you also want to match against other files in the same folder, not against the current file/folder.
Mr_Noodle
Site Admin
 
Posts: 11240
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support