Jump to content

Email Forward to specific address + No Signature


Recommended Posts

Good Morning, I have been working on my workflow recently with trello and a co worker, I have to constantly forward emails to them, I have two instances of my hotkey forward, which forwards the selected email to my coworker and one that forwards the message to my trello board to keep it as a to do item.

 

I have a workflow I made with some apple script I found that forwards the email in an ok fashion (not great) but the problem is it adds my signature so my trello board is now filled with my company logo, not very pretty. I have turned off the setting for adding the signature to quoted text but it still pops up in the forward.

 

So my question is, can someone give me a more elegant way to do this, or just help me tweak my code to make sure no signature is selected. I have created a blank signature title "none" I just dont know how to select it.

 

here is the code I am using now

___________________________________________________

 

on alfred_script(q)
  set myComment to "xxxx@boards.trello.com"
set theName to "Some name"
set theAddress to "Some email address"
 
try
    set the clipboard to myComment
    tell application "Mail"
        set theSelection to selection
        set theForwardedMessage to forward (item 1 of theSelection) with opening window
        tell theForwardedMessage
            make new to recipient at end of to recipients with properties {name:theName, address:theAddress}
        end tell
        activate
        tell application "System Events" to keystroke "v" using {command down}
        delay 1
        send theForwardedMessage
    end tell
end try
end alfred_script

 

 

___________________________________________________

 

thank you so much for anyone that can help!

Link to comment

It looks to me like this is a bug in AppleScript (on Sierra at least).  I tried a handful of Mail signature creation scripts and experimented with yours and none of them are working.  See also https://gist.github.com/Moligaloo/3850710 .  With Sal gone I fear it may never get fixed.

 

But....Mail Act-On Outbox rules do work, so presumably they're accessing the signature some other way.  It's $30 but if you work with a lot of email it's worth it IMHO.

Edited by dfay
Link to comment

Thank you for looking into that for me, I dont know enough about this stuff to implement it corectly, where would I put this code in my code?

 

new code

 

try 
set message signature of new_message to signature mySignature 

on error --BUG SIERRA 

tell application "Mail" to activate 
tell application "System Events" 
tell process "Mail" 
click pop up button 1 of window 1 
delay 0.1 
keystroke "g" --put here the first letter of the name of your signature 
delay 0.1 
keystroke return 
delay 0.1 
end tell 
end tell 


end try 

 

 

 

My code

 

on alfred_script(q)
  set myComment to "xxxx@boards.trello.com"
set theName to "Some name"
set theAddress to "Some email address"
 
try
    set the clipboard to myComment
    tell application "Mail"
        set theSelection to selection
        set theForwardedMessage to forward (item 1 of theSelection) with opening window
        tell theForwardedMessage
            make new to recipient at end of to recipients with properties {name:theName, address:theAddress}
        end tell
        activate
        tell application "System Events" to keystroke "v" using {command down}
        delay 1
        send theForwardedMessage
    end tell
end try
end alfred_script

Link to comment
set myComment to "xxxx@boards.trello.com"
set theName to "Some name"
set theAddress to "Some email address"
set mySignature to "blank"


try
	set the clipboard to myComment
	tell application "Mail"
		set theSelection to selection
		set theForwardedMessage to forward (item 1 of theSelection) with opening window
		tell theForwardedMessage
			make new to recipient at end of to recipients with properties {name:theName, address:theAddress}
		end tell
		activate
		tell application "System Events" to keystroke "v" using {command down}
		delay 1
		
		try
			set message signature of theForwardedMessage to signature mySignature
			
		on error --BUG SIERRA 
			
			tell application "Mail" to activate
			tell application "System Events"
				tell process "Mail"
					click pop up button 4 of window 1
					delay 0.1
					keystroke "b" --put here the first letter of the name of your signature 
					delay 0.1
					keystroke return
					delay 0.1
				end tell
			end tell
			
			
		end try
		
		-- send theForwardedMessage
	end tell
end try

this worked for me (commented out the send for testing)

 

this requires that you have a signature called "blank" that's active in the sending account

Edited by dfay
Link to comment

Thank you so much for your help so far, I am having no luck with this, I have set up blank signatures on all accounts, now when I hit the hotkey it puts the correct address in the sender but then just sits there and does not continue forward :( any ideas?

Link to comment

Hmm.  I did the 10.12.4 upgrade last night and now it needs to click pop up button 5 instead of 4 ... don't notice what changed in the UI but something must have.  You may need to do some trial and error to get the correct pop up button # -- I use Mail Add-On and MailTags which modify the Mail window, so the # of the button may be different in your case.  Such are the perils of being forced to use UI scripting.

 

It may be an issue with the way Alfred calls scripts, and the handling of subprocesses / System Events therein.  It's working for me with a Run Script > osascript (AS) > input as {query} object in the workflow.

 

But...I just checked and it works as Run NSApplescript as well.

 

Here's the exact code I am using with Run NSApplescript:

 

on alfred_script(q)
  set theQuery to q

set myComment to "xxxx@boards.trello.com"
set theName to "Some name"
set theAddress to "Some email address"
set mySignature to "blank"


try
	set the clipboard to myComment
	tell application "Mail"
		set theSelection to selection
		set theForwardedMessage to forward (item 1 of theSelection) with opening window
		tell theForwardedMessage
			make new to recipient at end of to recipients with properties {name:theName, address:theAddress}
		end tell
		activate
		tell application "System Events" to keystroke "v" using {command down}
		delay 1
		
		try
			set message signature of theForwardedMessage to signature mySignature
			
		on error --BUG SIERRA 
			
			tell application "Mail" to activate
			tell application "System Events"
				tell process "Mail"
					click pop up button 5 of window 1
					delay 0.1
					keystroke "b" --put here the first letter of the name of your signature 
					delay 0.1
					keystroke return
					delay 0.1
				end tell
			end tell
			
			
		end try
		
		-- send theForwardedMessage
	end tell
end try
  return theQuery
end alfred_script

 

Edited by dfay
Link to comment

Still having no luck with this, no errors kicking out, I dont know how to find the popup window is is supposed to be clicking, I do have the accessibility inspector but I dont know how to use it to find the numbers I need

 

I dont want to keep bothering you with this, so thank you so much for your help so far, I will just have to manualy delete the signature for now, not too big of a deal

 

Thank you again for all the help youve put into this over the past few days!

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...