Hazel to email new or modified files

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

Moderator: Mr_Noodle

Re: Hazel to email new or modified files Fri Oct 07, 2016 11:46 am • by jpscharf
Here is what worked for me:

Code: Select all
set subject_ to "Receipt (Automated)"
set the_content to "This is an automated receipt notification…"
set email_from to "to@example.com"
set email_to to "from@example.com"
tell application "Mail"
    set newMessage to make new outgoing message with properties {visible:true, subject:subject_, content:the_content}
    tell newMessage
       
        set visible to false
        set sender to email_from
        make new to recipient at end of to recipients with properties {address:email_to}
        try
            make new attachment with properties {file name:theFile as alias} at after the last paragraph
        on error errmess -- oops
            log errmess -- log the error
        end try
        delay 1
        (* 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
jpscharf
 
Posts: 1
Joined: Fri Oct 07, 2016 11:43 am

Re: Hazel to email new or modified files Tue Oct 11, 2016 2:46 pm • by rllewis
Almost there. It puts the contents into my "DRAFTS" folder and doesn't send it. (Note the instruction says "send" not "save."

Also, it creates two emails in the draft folder: one contains the folder and the other contains the folder's contents. I'm just interested in the contents. (I believe Hazel is doing this since I have a rule: "run rules on folder contents". Don't know how else to get it to send me the contents and not just the enclosing folder. But I'm ok with two emails if I could get this to work.

Thx!
rllewis
 
Posts: 8
Joined: Mon Feb 15, 2016 2:43 pm

Re: Hazel to email new or modified files Thu Feb 16, 2017 5:48 pm • by Wayhay
Hi I have managed to do this now using a combination of hazel And Automator. If anyone's interested I can go through the stages. I'm by no means an expert but it was surprisingly easier than I thought.

Let me know if your interested in the steps
Wayhay
 
Posts: 3
Joined: Tue Oct 13, 2015 4:39 pm

Re: Hazel to email new or modified files Fri Feb 17, 2017 1:14 am • by rllewis
Yes, very interested! Thanks
rllewis
 
Posts: 8
Joined: Mon Feb 15, 2016 2:43 pm

Re: Hazel to email new or modified files Sun Mar 04, 2018 2:05 am • by maddbishop
jpscharf wrote:Here is what worked for me:

Code: Select all
set subject_ to "Receipt (Automated)"
set the_content to "This is an automated receipt notification…"
set email_from to "to@example.com"
set email_to to "from@example.com"
tell application "Mail"
    set newMessage to make new outgoing message with properties {visible:true, subject:subject_, content:the_content}
    tell newMessage
       
        set visible to false
        set sender to email_from
        make new to recipient at end of to recipients with properties {address:email_to}
        try
            make new attachment with properties {file name:theFile as alias} at after the last paragraph
        on error errmess -- oops
            log errmess -- log the error
        end try
        delay 1
        (* 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



How could you add multiple recipients to the 'to'?
maddbishop
 
Posts: 1
Joined: Sun Mar 04, 2018 2:03 am

Re: Hazel to email new or modified files Tue Oct 30, 2018 9:39 am • by maxis
The same with Mojave. Not attaching the attachment.


kevinreynolds wrote: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
maxis
 
Posts: 1
Joined: Tue Oct 30, 2018 9:37 am

Re: Hazel to email new or modified files Tue Oct 30, 2018 10:01 am • by Mr_Noodle
Note that Mojave adds extra privacy protections, which include executing AppleScripts. Go to the Privacy settings in System Preferences. Make sure HazelHelper is in the Automation section and that any apps you want Hazel to access are checked.
Mr_Noodle
Site Admin
 
Posts: 8697
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Hazel to email new or modified files Fri Aug 02, 2019 1:04 pm • by iYura
Hazel log show this:

NSLocalizedDescription = "The variable theAttachment1 is not defined.";

Looks like script don't know this variable


maxis wrote:The same with Mojave. Not attaching the attachment.


kevinreynolds wrote: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
iYura
 
Posts: 1
Joined: Fri Jan 11, 2019 10:37 am

Re: Hazel to email new or modified files Mon Aug 05, 2019 8:57 am • by Mr_Noodle
I'd suggest displaying theFile and theAttachment1 to see what values they hold.
Mr_Noodle
Site Admin
 
Posts: 8697
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Previous

Return to Support

cron