Hello,
I made a script to notify me when new mails arrive in Eudora.
It works well.
But I would like to delete the return characters in the message notification to display (in growl) the maximum of the body message.
Here’s the part of the code to get the content of the new mails :
tell application "Eudora"
set NewMail to 0
set MyDisplaySenders to {}
set myDisplaySubjects to {}
set myDisplayBodies to {}
set DisplayMess to {}
set DisplaySub to {}
set DisplayBody to {}
repeat with MessNo from 1 to NbrMessNotification
set messStatus to the status of message MessNo in mailbox MailboxNotification of mail folder MailboxFolder
if messStatus is unread then
set mySender to sender of message MessNo in mailbox MailboxNotification of mail folder MailboxFolder
set mySubject to subject of message MessNo in mailbox MailboxNotification of mail folder MailboxFolder
set myBody to (body) of message MessNo in mailbox MailboxNotification of mail folder MailboxFolder
set DisplayMess to {mySender}
set DisplaySub to {mySubject}
set DisplayBody to {myBody}
set NewMail to (NewMail + 1)
end if
set MyDisplaySenders to MyDisplaySenders & DisplayMess
set myDisplaySubjects to myDisplaySubjects & DisplaySub
set myDisplayBodies to myDisplayBodies & DisplayBody
end repeat
So myDisplayBodies is a list of string.
And this list contain each body of new mails.
I made also some functions to remplace return character by space character :
on ReplaceReturnList(myList)
repeat with itemIndex from 1 to length of myList
set the item itemIndex of myList to ReplaceReturn(the item itemIndex of myList)
end repeat
return myList
end ReplaceReturnList
on ReplaceReturn(myString)
set myString to ReplaceString(myString, "
", " ")
set myString to ReplaceString(myString, "
", " ")
return myString
end ReplaceReturn
on ReplaceString(myString, OldCharacter, NewCharacter)
set text item delimiters of AppleScript to OldCharacter
set myTextList to text items of myString
set text item delimiters of AppleScript to NewCharacter
return myTextList as text
end ReplaceString
These functions work when I test them in script editor.
For example with :
return ReplaceReturnList({"go go go
go
go
go"})
But It doesn’t work in the full script.
Maybe because of some text format ?
If you have some idea …
Thanks
Christophe.
Full Script :
-- Required :
-- Eudora > Creation of a Notification mailbox
-- Creation of a "Copy to" filter to Notification mailbox for "any header" incoming mail
-- Growl > Optimized for Growl "Music Video" display
on run
tell application "System Events" to set ListProcesses to name of processes whose visible is true
if "Eudora" is not in ListProcesses then
set x to display dialog "Do you want to activate Eudora ?" buttons {"Yes", "No"} default button "Yes"
if button returned of x is "Yes" then
tell application "Eudora" to activate
end if
end if
end run
on idle
set Delay0 to 300 -- Check if Eudora is active with this delay
tell application "System Events" to set ListProcesses to name of processes whose visible is true
if "Eudora" is in ListProcesses then
set MailboxNotification to "Notification"
set MailboxFolder to ""
set Delay1 to 40 -- Check the mailbox with this delay
set IntervalDelay to Delay1
tell application "System Events" to set frontApp to (name of every process whose frontmost is true) as Unicode text
if frontApp is "Eudora" then
Notification2Trash()
end if
tell application "Eudora"
set NbrMessNotification to number of messages in mailbox MailboxNotification of mail folder MailboxFolder
end tell
if (NbrMessNotification > 0) then
tell application "Eudora"
set NewMail to 0
set MyDisplaySenders to {}
set myDisplaySubjects to {}
set myDisplayBodies to {}
set DisplayMess to {}
set DisplaySub to {}
set DisplayBody to {}
repeat with MessNo from 1 to NbrMessNotification
set messStatus to the status of message MessNo in mailbox MailboxNotification of mail folder MailboxFolder
if messStatus is unread then
set mySender to sender of message MessNo in mailbox MailboxNotification of mail folder MailboxFolder
set mySubject to subject of message MessNo in mailbox MailboxNotification of mail folder MailboxFolder
set myBody to (body) of message MessNo in mailbox MailboxNotification of mail folder MailboxFolder
set DisplayMess to {mySender}
set DisplaySub to {mySubject}
set DisplayBody to {myBody}
set NewMail to (NewMail + 1)
end if
set MyDisplaySenders to MyDisplaySenders & DisplayMess
set myDisplaySubjects to myDisplaySubjects & DisplaySub
set myDisplayBodies to myDisplayBodies & DisplayBody
end repeat
end tell
set myDisplayBodies to ReplaceReturnList(myDisplayBodies)
if (NewMail = 1) then
set NotificationMessage to ("You have " & NewMail & " new message")
else
set NotificationMessage to ("You have " & NewMail & " new messages")
end if
if (NewMail ≥ 1) then
tell application "GrowlHelperApp"
-- Make a list of all the notification types
-- that this script will ever send:
set the allNotificationsList to ¬
{"Eudora Notification", "Eudora Message"}
-- Make a list of the notifications
-- that will be enabled by default.
-- Those not enabled by default can be enabled later
-- in the 'Applications' tab of the growl prefpane.
set the enabledNotificationsList to ¬
{"Eudora Notification", "Eudora Message"}
-- Register our script with growl.
-- You can optionally (as here) set a default icon
-- for this script's notifications.
register as application ¬
"Eudora" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application "Eudora"
-- Send a Notification...
set NotificationBody to ""
repeat with itemIndex from 1 to NewMail
set messSubject to the item itemIndex of myDisplaySubjects
set messSender to the item itemIndex of MyDisplaySenders
set NotificationBody to NotificationBody & messSender & " - " & messSubject & return
end repeat
notify title ¬
"Eudora - " & NotificationMessage description ¬
NotificationBody with name ¬
"Eudora Notification" application name "Eudora"
repeat with itemIndex from 1 to NewMail
set messSubject to the item itemIndex of myDisplaySubjects
set messSender to the item itemIndex of MyDisplaySenders
set messBody to the item itemIndex of myDisplayBodies
notify title ¬
(messSender & " - " & messSubject) description ¬
messBody with name ¬
"Eudora Message" application name "Eudora"
end repeat
end tell
end if
end if
else
set IntervalDelay to Delay0
end if
return IntervalDelay
end idle
on reopen
set MessageExec to Notification2Trash()
end reopen
-- Notification2Trash : Delete all message in MailBox Notification
on Notification2Trash()
tell application "Eudora"
set MailboxNotification to "Notification"
set MailboxFolder to ""
if ((number of messages in mailbox MailboxNotification of mail folder MailboxFolder) > 0) then
repeat with MessNo from 1 to (number of messages in mailbox MailboxNotification of mail folder MailboxFolder)
set status of message 1 in mailbox MailboxNotification of mail folder MailboxFolder to "2"
set priority of message 1 in mailbox MailboxNotification of mail folder MailboxFolder to "180"
move message 1 in mailbox MailboxNotification of mail folder MailboxFolder to end of mailbox "Trash"
end repeat
end if
end tell
end Notification2Trash
on ReplaceReturnList(myList)
repeat with itemIndex from 1 to length of myList
set the item itemIndex of myList to ReplaceReturn(the item itemIndex of myList)
end repeat
return myList
end ReplaceReturnList
on ReplaceReturn(myString)
set myString to ReplaceString(myString, "
", " ")
set myString to ReplaceString(myString, "
", " ")
return myString
end ReplaceReturn
on ReplaceString(myString, OldCharacter, NewCharacter)
set text item delimiters of AppleScript to OldCharacter
set myTextList to text items of myString
set text item delimiters of AppleScript to NewCharacter
return myTextList as text
end ReplaceString
AppleScript: AppleScript 1.10.6
Browser: Safari 417.9.2
Operating System: Mac OS X (10.4)