Please keep considering the support for shell scripts.
There is a standard way to get the results from a shell script using the standard output (STDOUT) and standard error (STDERR) for verbose text and the process exit code. The "single number" you are referring to is the process exit code. It is great that you are using it to determine if the script passed or failed as that is the intended use.
My request is if you would add support to capture the standard output (STDERR probably isn't necessary). By default the output would be ignored and Hazel would just use the exit code as it is now but the user has the option to enable it.
Enabling it would require them to choose how Hazel handles the output.
- Capture all of the output and put it into a single Hazel token which could then be used in later rules
- Parse each line of the output and capture ONLY lines that contains Hazel-friendly text to be inserted into multiple tokens
I can see in the Hazel DEBUG output that you are already passing along the standard output of the script but just not doing anything with it yet.
- Code: Select all
2014-04-15 20:28:21.943 hazelworker[57439] DEBUG: == script output ==
argv: ['/Users/Smudge/bin/processFile.py', '/Users/Shared/TV/Processing/invader.zim.s01e01.avi']
Processing 'invader.zim.s01e01.avi'
GuessIt found: {
[1.00] "mimetype": "video/x-msvideo",
[1.00] "episodeNumber": 1,
[1.00] "container": "avi",
[0.50] "title": "The Nightmare Begins",
[0.70] "series": "Invader ZIM",
[1.00] "type": "episode",
[1.00] "season": 1
}
High enough confidence. Continuing on...
{hazelExportTokens:{series:'Invader ZIM'},{season:1},{episodeNumber:1}}
Renamed 'invader.zim.s01e01.avi' to 'Invader ZIM S01E01 The Nightmare Begins.avi'
{hazelSwitchFile:'/Users/Shared/TV/Processing/Invader ZIM S01E01 The Nightmare Begins.avi'}
== End script output ==
2014-04-15 20:28:21.943 hazelworker[57439] DEBUG: Shellscript /Users/Smudge/bin/processFile.py executed successfully with file /Users/Shared/TV/Processing/invader.zim.s01e01.avi
So in this example, Hazel would ignore the lines of output except
{hazelExportTokens:{series:'Invader ZIM'},{season:1},{episodeNumber:1}}
{hazelSwitchFile:'/Users/Shared/TV/Processing/Invader ZIM S01E01 The Nightmare Begins.avi'}
For these lines, it would create custom tokens for series, season, and episodeNumber then use the renamed file for further rule actions.
And just to throw a bit more into the request. Currently only the filename is passed to the script but it would be very useful to have Hazel pass any matched tokens from the rule set.
One idea is that you should be able to set them as prefixed environment variables when you call the shell script. For example if it matches to a custom token named 'foo', you would set the environment variable of '_hazel_foo' to the token value.
So there is plenty of info for you to think about. Hopefully you can consider this request for enhancement as it would greatly increase the flexibility of Hazel.
Thanks