Page 1 of 1

Feature Request: Hazel command line to start, stop or stat

PostPosted: Mon Feb 17, 2014 7:10 pm
by leoofborg
I'm looking for a way to *gracefully* manipulate Hazel from the command line. I tried recording turning Hazel on/off via AppleScript but recording doesn't seem to work in Mavericks:

http://www.noodlesoft.com/forums/viewtopic.php?f=4&t=714&hilit=Helper

If there was a CLI command like 'hazel' I'd be typing

* hazel -start = Turns on as in the GUI

* hazel -stop = Turns off as in the GUI

* hazel -stat = Returns the status, is it on or off?

Maybe even:

* hazel -toggle

Why? I'm automating things on my Mac(s), using Otto's Remote, which allows pushing of shellscripts, Automator or AppleScript from your iphone/iPad to a Mac:

http://ottosantenna.com/

When I'm upgrading, it'd be nice to push a 'turn off' command to my machines without having to VNC in and wait 10 seconds between mouse movements in the OSX GUI.

Re: Feature Request: Hazel command line to start, stop or st

PostPosted: Tue Feb 18, 2014 4:57 pm
by Mr_Noodle
No way to do that currently though I'm still unclear on why you need it. What are you upgrading and why does Hazel need to be stopped then?

Re: Feature Request: Hazel command line to start, stop or st

PostPosted: Fri Feb 21, 2014 5:06 am
by leoofborg
As you've mentioned previously, Hazel kind of works in an an asynchronous way. 'killing' it from the Terminal has also been mentioned to be 'bad'... So there are two reasons why Hazel should be open to CLI:

(1) My workflow, remoting into a Mini, which I'll explain, and

(2) To make Alfred or Automator (HotKey, Service Menu) Workflows which can be invoked via CLI glue.

So: (1)

When I'm working on my my remote Mini, via *two* crappy, latent ISP connections, I need all the speed I can get. If I upgrade/trash a bunch of Apps, I don't need Hazel running its 'okay now scan trash and throw that dialog' when I'm remoting in from 200 miles away. So there's a whole 'Go to SysPrefs, turn off Hazel, do work'... all being done at 10 frames per second tedious SLOW. The rest of the work at that speed is too. :|

I've mitigated a LOT of this with Otto. I can run automator actions or CLI without ssh'ing in (Otto uses iCloud to pass commands to the right machine regardless of remote ip address!!). So I'm able to 'semi-automatically' use Otto to queue software downloads and even move files into folders that (when I turn it back on, yup via Otto) Hazel can process. This. is. really. nice. and. powerful. Which brings me to number 2:

(2)

If I have CLI glue, I can also make triggers that I can invoke from Alfred *and/or* the Services Menu, locally. Meaning I can also make 'hot key' bindings. Here's a MESSY shell script to kill DropBox I made:

Code: Select all
#!/bin/bash

killall Dropbox

/usr/local/bin/growlnotify -m "Otto DB Kill fired."


DropBox doesn't 'mind' being killed, as the files will be re-sync'd and conflicts addressed. But if Hazel needs 'graceful exit' then when I make this script for Alfred:

Code: Select all
#!/bin/bash

hazel -stop

/usr/local/bin/growlnotify -m "Hazel has been stopped"


..start would be the same, and for the stat command, off the top of my head, this:

Code: Select all
#!/bin/bash

/usr/local/bin/growlnotify -m < echo | hazel -stat


to return the status... My shell-echo redirect is a bit rusty.

I hope this makes sense. If the feature is implemented, I'd first use it with Otto, then make Alfred commands in short order. For automator Service menu-hotkeys, the command might take this form:

See a mock here: https://www.dropbox.com/s/u9l6kv6x9xjb2vj/Hazel_Automator_mock.png

I hope this makes sense... :D

Re: Feature Request: Hazel command line to start, stop or st

PostPosted: Fri Feb 21, 2014 4:13 pm
by Mr_Noodle
Thanks for the description. Some of this seems very special case. I think I already have a feature request for this but I can't say it's a high priority item but I will think about it. You may want to look into Automator's "record" functionality to automate manipulating the UI. I haven't used it myself but it may work.

Re: Feature Request: Hazel command line to start, stop or st

PostPosted: Tue Feb 25, 2014 3:41 am
by leoofborg
Mr_Noodle wrote:Thanks for the description. Some of this seems very special case. I think I already have a feature request for this but I can't say it's a high priority item but I will think about it. You may want to look into Automator's "record" functionality to automate manipulating the UI. I haven't used it myself but it may work.


Mr. Noodle: I've found a VERY brutish "solution".. it's one that I think we all want to avoid. But, for remote machines where there's no other alternative I offer it.

Recording, either by Applescript or Automator just does not work. I'll break down what I found:

1/ Applescript doesn't even *see* anything to record. I guess you can't see right side menu items. Can't see can't record. At all.

2/ Automator, however, *can* see that it's talking to the HazelHelper process. BUT "Click the "<fill in title>" menu" only works when pressing 'Play' in the Automator GUI, and it makes a handy "Toggle".. but once put in a workflow or made into an App it fails, because, again, there's no name of that menuitem.

So I can partially talk to HazelHelper. And I did learn that HazelHelper runs as a *user* and not *system* process. So, from the terminal you can use:

Code: Select all
open -a HazelHelper


To launch it. Invoking open -a doesn't spawn multiple processes of the same helper so this might be useful. Stopping is the brutish:

Code: Select all
killall HazelHelper


Which will kill all (one, hopefully) instances of Hazel, until you use Open or go to the System Preferences.

I'll probably use this with Otto's Remote to start/stop things from afar... but I'm not going to be making 'hotkeys' with this.. there is no graceful exit from doing a task, it is a variant of *kill* after all....It's not just 'turning off' Hazel, but quitting the process that that also runs the menuitem as well.

Re: Feature Request: Hazel command line to start, stop or st

PostPosted: Wed Apr 13, 2016 12:53 am
by gaseous1
This can very easily be handled in an elegant manner by Keyboard Maestro. KM allows an incredible depth of UI and program control and is an integral part of my daily workflow. I have used the program for several years, and like any sufficiently powerful tool, it has a learning curve. The user forum is an excellent place to find suggestions and examples, as are numerous other sites where users have posted solutions to problems.

In short, using KM, the actual "macro" steps are:

Activate System Preferences (and bring it frontmost)
Pause Until Conditions Met (System Preferences is frontmost)
Pause Until Conditions Met (a menu with the name "General" is enabled)
Pause for .1 Seconds
Select ‘Hazel’ in the Menu ‘View’ in System Preferences
Pause Until Conditions Met (a button named "Folders" exists)
Press Button ‘Info’
If All Conditions Met Execute Actions (check for a button named 'Stop Hazel')
Press Button 'Stop Hazel'

It's really quite straightforward, and the macro can be tested as you develop it. This macro could also be improved to give a warning if Hazel didn't exist, for example. For my intentions it works very well, though. Finally, this macro can be treated as a subroutine, and can be called from another macro, making development of workflows easier and more compact.

Regards,

Eric

Re: Feature Request: Hazel command line to start, stop or st

PostPosted: Fri Sep 15, 2017 9:05 am
by jamwithtoast
Hi Eric,
Are you able to post your KM script?

I can't seem to find 'Activate System Preferences' for the life of me... ;(
thanks j

Re: Feature Request: Hazel command line to start, stop or st

PostPosted: Fri Sep 15, 2017 10:56 am
by gaseous1
The step you are having difficulty finding is the "Activate a Specific Application" action.

Cmd-K, in the KM Editor, brings up the action window. Select the "Application Control" folder in the resulting window and the aforementioned action will be listed. Alternatively, using the menu system, choosing Edit -> Insert Action -> Application Control -> Activate a Specific Application, achieves the same effect.

The only thing left is to select "System Preferences" within the action.

I will try and post the macro later.

Regards,

Eric


jamwithtoast wrote:Hi Eric,
Are you able to post your KM script?

I can't seem to find 'Activate System Preferences' for the life of me... ;(
thanks j

Re: Feature Request: Hazel command line to start, stop or st

PostPosted: Wed Apr 04, 2018 8:51 pm
by jhein
AppleScript:

Code: Select all
tell application id "com.noodlesoft.HazelHelper"
   if it is running then
      tell it to quit
   else
      tell it to run
   end if
end tell

Re: Feature Request: Hazel command line to start, stop or st

PostPosted: Wed Apr 04, 2018 11:06 pm
by gaseous1
The AppleScript works well, but with one proviso. Hazel remembers its state between starts, i.e. whether it was in the Started or Stopped state. If Hazel is run, after quitting when Hazel is in the Stopped state, then Hazel will not process any rules.

Thank you for the script!

Regards,

Eric

jhein wrote:AppleScript:

Code: Select all
tell application id "com.noodlesoft.HazelHelper"
   if it is running then
      tell it to quit
   else
      tell it to run
   end if
end tell