Last active
August 29, 2015 14:05
-
-
Save chaseroden/77a0253f2c3009eb22aa to your computer and use it in GitHub Desktop.
AppleScript to forward emails to Zendesk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set target_string to "\\" | |
set zendeskAddress to "[email protected]" | |
-- This script forwards an email from Outlook 2011 to your Zendesk support address, provided above. | |
-- Specifically, it checks your clipboard for a Zendesk message ID and adds it to the subject line if one is there. | |
-- If there isn't a Zendesk ID in the format [XXXX-XXXX] somewhere on your clipboard, it asks for one. | |
-- It adds the original sender of the email as the ticket's #requester and marks it a private #note on the ticket. | |
-- Presently it doesn't forward attachments. | |
-- To do: have it remove the agent's signature from the message. | |
-- Chase Roden <[email protected]> | |
tell application "Microsoft Outlook" | |
set selectedMessages to current messages | |
if selectedMessages is {} then | |
display dialog "Please select a message first and then run this script." with icon 1 | |
return | |
end if | |
repeat with theMessage in selectedMessages | |
-- get the information from the message, and store it in variables | |
set theSubject to subject of theMessage | |
set theCategory to category of theMessage | |
set theSender to sender of theMessage | |
set senderAddress to address of theSender | |
if has html of theMessage then | |
set theContent to content of theMessage | |
else | |
set theContent to plain text content of theMessage | |
end if | |
end repeat | |
-- Checks the clipboard to see if there's a Zendesk email ID in there, returns 0000 if not | |
set cbContents to the clipboard | |
set checkClipboardCommand to "echo -e " & quoted form of cbContents & " | grep -oe \\\\[....\\-....\\\\] || echo '0000'" | |
set clipboardNumber to (do shell script checkClipboardCommand) | |
-- Uses the ID from the clipboard in the subject of a new message or asks for an ID | |
if clipboardNumber is not "0000" then | |
set newSubject to theSubject & " " & clipboardNumber | |
set newHeaders to "#note<br>" | |
else | |
display dialog "Enter ticket ID" default answer "" | |
set ticketID to text returned of result | |
set newSubject to theSubject & " " & ticketID | |
if ticketID = "" then | |
set newHeaders to "#note<br>#requester " & senderAddress & "<br><br>" | |
else | |
set newHeaders to "#note<br>" | |
end if | |
end if | |
set newContent to newHeaders & theContent | |
set newMessage to make new outgoing message with properties {subject:newSubject, content:newContent} | |
make new recipient of newMessage with properties {email address:{address:zendeskAddress}} | |
open newMessage | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment