[GastForen Programmierung/Entwicklung AppleScript ein KOmma zu viel ;-)

  • Suche
  • Hilfe
  • Lesezeichen
  • Benutzerliste
Themen
Beiträge
Moderatoren
Letzter Beitrag

ein KOmma zu viel ;-)

ray10969
Beiträge gesamt: 2

3. Okt 2016, 19:36
Beitrag # 1 von 3
Bewertung:
(1523 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo Zusammen :-)

Ich verwende dieses applescript um email-absender in ein text-file zu schreiben (durch Komma getrennt) funktioniert super aber nach dem letzten Eintrag steht in dem text-file natürlich auch ein Komma und das soll da auf keinen Fall stehen
:-(

Wer hat eine Idee?

Danke :-)

tell application "Mail"
set selectionMessage to selection -- just select the first message in the folder
set thisMessage to item 1 of selectionMessage
set theseMessages to (every message in (mailbox of thisMessage))
set listOfEmails to {}
repeat with eachMessage in theseMessages
try
set theFrom to (extract address from sender of eachMessage)
if listOfEmails does not contain theFrom then
copy theFrom to the end of listOfEmails
end if


end try
end repeat
end tell
tell application "Finder" to set ptd to path to documents folder as string
set theFile to ptd & "daily-abo-list.txt"
set theFileID to open for access theFile with write permission
set SortedListOfEmails to simple_sort(listOfEmails)
repeat with i from 1 to count of SortedListOfEmails


write item i of SortedListOfEmails & "," to theFileID as «class utf8»
end repeat
close access theFileID

on simple_sort(my_list)
set the index_list to {}
set the sorted_list to {}
repeat (the number of items of my_list) times
set the low_item to ""
repeat with i from 1 to (number of items of my_list)
if i is not in the index_list then
set this_item to item i of my_list as text
if the low_item is "" then
set the low_item to this_item
set the low_item_index to i
else if this_item comes before the low_item then
set the low_item to this_item
set the low_item_index to i
end if
end if
end repeat
set the end of sorted_list to the low_item
set the end of the index_list to the low_item_index
end repeat
return the sorted_list
end simple_sort
X

ein KOmma zu viel ;-)

Hans Haesler
  
Beiträge gesamt: 5826

3. Okt 2016, 20:06
Beitrag # 2 von 3
Beitrag ID: #553002
Bewertung:
(1507 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo Ray,

herzlich willkommen im AppleScript-Forum auf HDS! :-)

Versuche es bitte mal so:

Code
repeat with i from 1 to (count of SortedListOfEmails) - 1 
write item i of SortedListOfEmails & "," to theFileID as «class utf8»
end repeat
write item (i + 1) of SortedListOfEmails to theFileID as «class utf8»

Die Schleife wird um einen Umgang weniger durchlaufen.
Und anschliessend wird nur das letzte Element dazugeschrieben.

Gruss, Hans


als Antwort auf: [#553001]

ein KOmma zu viel ;-)

ray10969
Beiträge gesamt: 2

3. Okt 2016, 20:36
Beitrag # 3 von 3
Beitrag ID: #553003
Bewertung:
(1485 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Genial :-)

Danke für die superschnelle Antwort

:-)


als Antwort auf: [#553002]