Filename to include text based upon a keyword in the file
I am new to Hazel and am attempting my first “scripts”. I may be getting off on the wrong foot…
Consider a file ‘foo.pdf’.
Within file “foo.pdf” there are certain text strings:
I wish to perform the following actions:
Examples:
The best I’ve been able to solve this is as follows:
My Hazel solution seems very… obtuse… wordy…
Is there a better way?
What am I not understanding concerning “The Hazel Way”?
Should I just drop into Apple Shortcuts or a Shell script?
Is there an accepted convention of translating the Hazel GUI code into text for discussion?
Thank you in advance!
XD-2
"Mission Control, this is X-ray-Delta-Two, two-one-zero-three transmission concluded."
Consider a file ‘foo.pdf’.
Within file “foo.pdf” there are certain text strings:
- “heading 1 text_1”
“heading 2 text_2”
I wish to perform the following actions:
- Code: Select all
retrieve text_1 & text_2
if text_1 = “alpha”
filename := “omega gamma text_2.pdf”
else if text_1 =“beta”
filename := “omega delta text_2.pdf”
else
the usual exceptions
end if
rename “foo.pdf” to filename
move file to folder folder_1
Examples:
- Code: Select all
File contains “heading 1 alpha heading 2 what_ever”.
File renamed to “omega gamma what_ever.pdf”
File contains “heading 1 beta heading 2 what_ever”.
File renamed to “omega delta what_ever.pdf”
The best I’ve been able to solve this is as follows:
- Code: Select all
Rule 1
If all of the following conditions are met
Full Name is foo.pdf
Contents contain match “heading 1 “<retrieve 1>
Contents contain match “heading 2 “<retrieve 2>
Do the following…
Rename with pattern: “omega <retrieve 1> <retrieve 2>.pdf”
Rule 2
If all of the following conditions are met
Name contains “alpha”
Do the following…
Rename with pattern > Replace “alpha” with “gamma”
Rule 3
If all of the following conditions are met
Name contains “beta”
Do the following…
Rename with pattern > Replace “beta” with “delta”
Rule 4
If all of the following conditions are met
Name contains “omega”
Do the following…
Move file to folder _1
My Hazel solution seems very… obtuse… wordy…
Is there a better way?
What am I not understanding concerning “The Hazel Way”?
Should I just drop into Apple Shortcuts or a Shell script?
Is there an accepted convention of translating the Hazel GUI code into text for discussion?
Thank you in advance!
XD-2
"Mission Control, this is X-ray-Delta-Two, two-one-zero-three transmission concluded."