Hazel to email new or modified files

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

Moderator: Mr_Noodle

Hazel to email new or modified files Fri Mar 28, 2014 12:29 pm • by Thwiipp
Hello, I'm trying to have Hazel monitor a folder and send an email to a few recipients when new items are added or existing ones are modified. I have this setup:
Imagewith the following applescript:

Code: Select all
set theAttachment1 to (POSIX path of theFile)
set subject_ to "SUBJECT"
set the_content to "CONTENT"
tell application "Mail"
   set newMessage to make new outgoing message with properties {subject:subject_, content:the_content & return & return}
   tell newMessage
      
      set visible to false
      set sender to "my1@mac.com"
      make new to recipient at end of to recipients with properties {address:"my1@mac.com"}
      make new attachment with properties {file name:theAttachment1} at after the last paragraph
      
      (* change save to send to send*)
      send --<<<<---------------- change save to send to send or send to save to save to drafts
      (* change save to send to send*)
   end tell
end tell


It seems to work well with the exception if it is more than one file it will send one email for each file. If i update 20 files, i don't want the system to send out 20 different email messages for one update. Anyone have any idea how i can fix this? Thanks
Thwiipp
 
Posts: 6
Joined: Fri Mar 28, 2014 11:53 am

Re: Hazel to email new or modified files Fri Mar 28, 2014 2:58 pm • by Mr_Noodle
The rules match a file at a time so that is how things work. If you only want one email notification, you should consider setting things up so that Hazel is matching against the folder instead of individual files.

One thing that will help here is if you hold down option while clicking the + button to create a condition. That will create a nested condition. There you can put conditions that will be used against the files in the folder but overall allow the rule to match the folder itself. Like, match the folder which has a file that was added or modified today.
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Hazel to email new or modified files Fri Mar 28, 2014 4:50 pm • by Thwiipp
Hi thanks for the reply,

I tried this, but still get the same results
Image
Thwiipp
 
Posts: 6
Joined: Fri Mar 28, 2014 11:53 am

Re: Hazel to email new or modified files Mon Mar 31, 2014 11:21 am • by Mr_Noodle
That's still going to match per file. You need to monitor one folder level up and then create a rule to match the folder.
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Hazel to email new or modified files Mon Mar 31, 2014 12:31 pm • by Thwiipp
Ok I moved it up one level, its a step in the right direction, but now it tries to attach the contents of the entire folder each time, even though only a few files meet the criteria of being created or modified today.

Image
Thwiipp
 
Posts: 6
Joined: Fri Mar 28, 2014 11:53 am

Re: Hazel to email new or modified files Tue Apr 01, 2014 3:24 pm • by Mr_Noodle
You'll probably need to have the script pick out the right files as it's being passed in the whole folder.
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Hazel to email new or modified files Tue Apr 01, 2014 4:11 pm • by Thwiipp
OK, do you have any suggestions, i got some help with my initial code online, not that adept with apple script. Thanks
Thwiipp
 
Posts: 6
Joined: Fri Mar 28, 2014 11:53 am

Re: Hazel to email new or modified files Wed Apr 02, 2014 2:17 pm • by Mr_Noodle
It's a bit outside the support I can give but I suggest googling around for how to do this. Or maybe someone else can chime in here with specific suggestions.
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Hazel to email new or modified files Thu Apr 03, 2014 4:22 pm • by Thwiipp
After looking it over i realized its trying to attach the whole folder because once a file within is updated of modified OS X marks the folder itself as updated. How do set Hazel to ignore the folder's properties and only pay attention to the files that we're just added?
Thwiipp
 
Posts: 6
Joined: Fri Mar 28, 2014 11:53 am

Re: Hazel to email new or modified files Fri Apr 04, 2014 2:33 pm • by Mr_Noodle
As mentioned earlier, you are given the folder, you have to then go through it and pick out the files. You can't have it both ways. You either have it match the folder so that it fires once, or it matches each individual file, but fires for each file.
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Hazel to email new or modified files Fri Apr 04, 2014 4:09 pm • by Thwiipp
OK I get that, so i figured i would set up a new folder where new items can go , and after they are emailed can be moved to where all the preexisting files are. The problem is that it goes back to sending the individual files instead of the contents of that folder. This new folder is located with the main folder because it needs to be
Thwiipp
 
Posts: 6
Joined: Fri Mar 28, 2014 11:53 am

Re: Hazel to email new or modified files Mon Apr 07, 2014 2:57 pm • by Mr_Noodle
Then again, you'll need to rework things to match the folder containing the files and not the files themselves, which is what seems to be happening.
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

We have just found that this code does not attach the document when using Mac El Capitan - the mail is created - yet the file attachment does not happen. It has worked fine for years - had to revert to normal Yosemite laptop and worked fine. ANY IDEAS?

Code: Select all
set theAttachment1 to (POSIX path of theFile)
set subject_ to "Your Data Sheet for XYZ"
set the_content to "Hello,

Attached is your monthly info....

tell application "Mail"
   set newMessage to make new outgoing message with properties {subject:subject_, content:the_content & return & return}
   tell newMessage
      
      set visible to false
      set sender to "me@me.com"
      make new to recipient at end of to recipients with properties {address:"thingy@bob.com"}
      make new attachment with properties {file name:theAttachment1} at after the last paragraph
      
      (* change save to send to send*)
      send --<<<<---------------- change save to send to send or send to save to save to drafts
      (* change save to send to send*)
   end tell
   
end tell
kevinreynolds
 
Posts: 2
Joined: Wed Sep 02, 2015 5:27 am

Re: Hazel to email new or modified files Wed Sep 02, 2015 12:28 pm • by Mr_Noodle
Probably a bug with El Cap. Have you tried the script outside Hazel? If it doesn't work there then you should definitely file a bug with Apple.
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Hazel to email new or modified files Mon Oct 12, 2015 12:13 pm • by Mr_Noodle
I think your problem may be a bit different. Were you the one that emailed this in? If so, I've already responded there so let's continue the discussion via email.
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Next

Return to Support