{"id":697,"date":"2017-09-27T14:40:34","date_gmt":"2017-09-27T21:40:34","guid":{"rendered":"http:\/\/10.0.1.201\/?p=697"},"modified":"2017-09-27T14:40:34","modified_gmt":"2017-09-27T21:40:34","slug":"parse-e-mail-for-ups-tracking-numbers","status":"publish","type":"post","link":"https:\/\/strawhousepig.net\/wordpress\/2017\/09\/27\/parse-e-mail-for-ups-tracking-numbers\/","title":{"rendered":"Parse e-mail for UPS tracking numbers"},"content":{"rendered":"<p>This AppleScript will parse the selected e-mail in Mail.app for UPS tracking numbers and will open the tracking page of the UPS website in your default browser.<\/p>\n<p>This only looks at a single e-mail, but could be made to repeat through multiple selections.<\/p>\n<p><code>tell application \"Mail\"<br \/>\n\tset _messages to selection as list<br \/>\n\tset input to content of item 1 of _messages<br \/>\n\ttry<br \/>\n\t\topen location my parse_nums(input)<br \/>\n\ton error<br \/>\n\t\tdisplay dialog \"No UPS tracking info found.\"<br \/>\n\tend try<br \/>\nend tell<\/p>\n<p>on parse_nums(input)<br \/>\n\tset input_new to \"\"<br \/>\n\tset output to \"\"<br \/>\n\tset input to every word of input<br \/>\n\trepeat with i in input<br \/>\n\t\ttry<br \/>\n\t\t\tif first character of i is \"1\" and second character of i is \"Z\" then --Every UPS # I've seen starts with '1Z'<br \/>\n\t\t\t\tset input_new to input_new & i & \"%0D%0A\" as string --<br \/>\nURL encoded carriage return line feed needed for multiple entries.<br \/>\n\t\t\tend if<br \/>\n\t\tend try<br \/>\n\tend repeat<br \/>\n-- Now to remove the last set of new line characters.<br \/>\n\trepeat with c in characters 1 through ((count of characters of input_new) - 6) of input_new<br \/>\n\t\tset output to output & c<br \/>\n\tend repeat<br \/>\n\tset the_URL to \"https:\/\/wwwapps.ups.com\/WebTracking\/track?track.x=Track&trackNums=\" & output<br \/>\n\treturn the_URL<br \/>\nend parse_nums<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This AppleScript will parse the selected e-mail in Mail.app for UPS tracking numbers and will open the tracking page of the UPS website in your default browser. This only looks at a single e-mail, but could be made to repeat through multiple selections. tell application &#8220;Mail&#8221; set _messages to selection as list set input to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[10],"class_list":["post-697","post","type-post","status-publish","format-standard","hentry","category-code","tag-applescript-2"],"_links":{"self":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/posts\/697","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/comments?post=697"}],"version-history":[{"count":0,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/posts\/697\/revisions"}],"wp:attachment":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/media?parent=697"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/categories?post=697"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/tags?post=697"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}