Wednesday, July 24, 2019

#1 2019-03-22 01:32:11 am

Blumea
Member
Registered: 2019-02-05
Posts: 1

Change email subject

Hi,

For archive purpose, I'd like to be able to "tag" the subject of emails (without using the tags, I would have hundreds of them). So I want to add some key words in the subject itself.

However I didn't find a way to change the subject of an email. I moved recently on Mac, and I knew how to do that in Windows, but here I didn't find a way.

This return a script error "Mail got an error: Can’t set subject of message"

Applescript:


tell application "Mail"
   set theMessage to item 1 of (the selection as list)
   set the subject of theMessage to my getNewSubject(subject of theMessage)
end tell

on getNewSubject(OldSubject)
   return text returned of (display dialog "Enter the new subject of the message and press Enter." default answer OldSubject)
end getNewSubject

Any Idea ?

Operating System: macOS 10.14

Last edited by Blumea (2019-03-22 01:33:17 am)


Filed under: mail, subject

Offline

 

#2 2019-03-22 02:35:50 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3472

Re: Change email subject

The dictionary ruling interaction between AppleScript and Mail is clear which states :

subject (text, r/o) : The subject of the message

r/o means read only.

We can't edit this property.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 22 mars 2019 09:35:45

Offline

 

#3 2019-03-25 02:08:59 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 239

Re: Change email subject

Blumea wrote:

Hi,

For archive purpose, I'd like to be able to "tag" the subject of emails (without using the tags, I would have hundreds of them). So I want to add some key words in the subject itself.

However I didn't find a way to change the subject of an email. I moved recently on Mac, and I knew how to do that in Windows, but here I didn't find a way.

This return a script error "Mail got an error: Can’t set subject of message"

Any Idea ?
Operating System: macOS 10.14



Hey. What you need is:

1) get the contents of the message in a variable:

Applescript:


tell application "Mail"
set the_message to item 1 of (get selection)
set message_text to content of the_message
end tell

2) Change the content of the message to the one you need. I show the idea. Your specific implementation will depend on the structure of the received messages. Like that:

Applescript:


set message_subject_line to "BLA_BLA_BLA_BLA..."
set message_dates_line to paragraph 3 of message_text
set message_location_line to paragraph 4 of message_text

set the_summary to message_subject_line & return & message_location_line

set the_meeting_date to ¬
word 3 of message_dates_line & space & ¬
word 4 of message_dates_line & ", " & ¬
word 5 of message_dates_line

set the_start_time to ¬
word 6 of message_dates_line & ":" & ¬
word 7 of message_dates_line & space & ¬
word 8 of message_dates_line

set the_end_time to ¬
word 9 of message_dates_line & ":" & ¬
word 10 of message_dates_line & space & ¬
word 11 of message_dates_line

set start_date to date (the_meeting_date & space & the_start_time)
set end_date to date (the_meeting_date & space & the_end_time)

3) Add through iCal new event. In essence, this creates a new message. Like that:

Applescript:


tell application "iCal"
tell calendar 1
make new event at end with properties ¬
{start date:start_date, end date:end_date, ¬
summary:the_summary, status:confirmed}
end tell
end tell

4) Delete the old message from the mail. Well, it is you yourself.

Last edited by KniazidisR (2019-03-25 02:48:04 am)


macOS Mojave -- version 10.14.4
Safari -- version 12.1

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)