RTF als Email-Formatvorlage

23/03/2011
Sagen wir mal ich habe hier eine RTF-Datei die so aussieht:

Hey REPLACEME1,


how you are doing. Do you have time for REPLACEME2?


Yours REPLACEME3

Dann baut sich dieses Skript hier:

set mytemplate to choose file


set replace_list to {"my friend", "what ever", "hubionmac"}

set replace_markers to {}

repeat with i from 1 to count of replace_list

set replace_markers to replace_markers & {"REPLACEME" & i}

end repeat


tell application "TextEdit"

set mytextfile to open mytemplate

set mytext_parts to attribute run of mytextfile

set mylayout to properties of attribute run of mytextfile

close mytextfile

end tell

repeat with i from 1 to count of replace_list

repeat with k from 1 to count of mytext_parts

set item k of mytext_parts to my replace_chars(item k of mytext_parts as text, item i of replace_markers as text, item i of replace_list as text)

end repeat

end repeat


set mytext to mytext_parts as text


tell application "Mail"

activate

set myMessageText to make new outgoing message with properties {content:mytext, visible:true}

tell myMessageText

set globalcounter to 1

set pointer to 1

repeat with i from 1 to count of mytext_parts

set currentcount to count of every character of item i of mytext_parts

set font of characters globalcounter through (globalcounter + currentcount - 1) to (font of item i of mylayout)

set size of characters globalcounter through (globalcounter + currentcount - 1) to (size of item i of mylayout)

set color of characters globalcounter through (globalcounter + currentcount - 1) to (color of item i of mylayout)

set globalcounter to globalcounter + currentcount

end repeat

(**

--this does not work 100% since set word i does not wait for the command to finish

repeat with i from 1 to count of every word

set myword to word i

if myword is in replace_markers then

set word i to (item ((characters 14 through -1 of (myword as text)) as text as integer) of replace_list) as text

end if

end repeat**)

end tell

end tell


on replace_chars(this_text, search_string, replacement_string)

if this_text contains the search_string then

set od to AppleScript's text item delimiters

set AppleScript's text item delimiters to the search_string

set the item_list to every text item of this_text

set AppleScript's text item delimiters to the replacement_string

set this_text to the item_list as string

set AppleScript's text item delimiters to od

end if

return this_text

end replace_chars

.. aus dieser Vorlage eine neue Email, dessen Text entsprechend formatiert ist. Der Gag dabei ist die Geschwindigkeit und die Tatsache, dass das Ding ohne Zwischenablage und GUI-Skripting die Stil-Angaben der Vorlage übernimmt.
No Comments

Finder: Move biggest file of folders to first folder

16/04/2010
Ein paar Ordner auswählen und die jeweils größte Datei wird in den ersten Ordner bewegt... Ich kann es gebrauchen, sag' aber nicht weshalb ;-P
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

tell application "Finder"

set these to selection

set folderkind to kind of folder 1 of startup disk

set movetothisfolder to ""

repeat with this in these

if kind of this is folderkind then

if movetothisfolder = "" then

set movetothisfolder to this

end if

set these2 to every item of this

set biggestsize to 0

repeat with this2 in these2

if size of this2 > biggestsize then

set biggestsize to size of this2

set movethis2 to this2

end if

end repeat

move movethis2 to movetothisfolder

end if

end repeat

end tell

No Comments

Dateigröße in Kilobyte, auch für Ordner

27/03/2010
Die Größe von Ordner kann man anscheinend über den Finder nicht so ohne weitere berechnen lassen, also:
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

tell application "Finder"

set mydesktop to desktop as alias

set desktopsize to my sizeof(mydesktop)

end tell


to sizeof(a)

set a to quoted form of (POSIX path of (a))

return (word 1 of ((do shell script "du -ks " & a)) as integer)

end sizeof

No Comments

Safari XY

13/12/2009
compass-copy.pngIch habe in letzter Zeit etwas mit JavaScript-Befehlen in Safari herumgespielt. Dabei bin ich dann auch auf die Idee gekommen mal die Fenster darüber zu verschieben und in der Größe zu verändern.Am Ende ist es doch aber recht dumm, wenn man über irgendwelche Formeln Fenster genau aufteilt, jeder hat da seine eigene praktische Anordnung, warum also diese nicht einmal einrichten und dann immer wieder aufrufen können.Das Skript kommt nun also vollkommen ohne Java-Script aus und funktioniert wie folgt:
Wenn man es das erste Mal mit einer bestimmten Anzahl an offenen Safari-Fenstern öffnet, speichert es deren Position ab.Ruft man das Skript nun später wieder auf, kennt es ja für diese Anzahl an Fenstern deren Position und stellt diese wieder her. Man kann diese Einstellung natürlich auch überschreiben, das bietet der Dialog auch an.So kann man sich für jede x-beliebige Anzahl an Safari-Fenstern, deren Position speichern und wieder herstellen =)Hier also Hubi's Safari XY Skript =) DOWNLOAD
Safari XY v.1.0
(227 hits)
HA, hier ist wohl die bessere Lösung
No Comments

Größe der Mailbox berechnen

8/05/2009
AppleScript Mailbox Size

Hm, wenn ich das richtig sehe, bekommt man in Apple Mail nicht wirklich die Größe einer einzelnen Mailbox heraus. Schon die Größe der Postfächer auf dem IMAP Server, aber bei POP3 wohl nur die der auf dem Server gespeicherten Emails. Jetzt könnte man natürlich in ~/Library/Mail einfach nachsehen oder sich die schlaflose Nacht mit einem AppleScript vertreiben:

Code zum markieren einmal anklicken

-- Mailbox Size Script


--  Created by Hubi on 08.05.2009

--  Copyright 2009 hubionmac.com. All rights reserved.

set c_date to do shell script "date '+%d.%m.%Y'"

set myoutput to "Mailstats vom " & c_date & return

do shell script "echo " & quoted form of myoutput & "| cat>/tmp/mailboxsize_" & c_date & ".txt"

tell application "Mail"

set accountlist to name of every account

set accountlist to (choose from list accountlist with multiple selections allowed)

if (count of accountlist) > 0 then

repeat with c_account in accountlist

set myoutput to "Account-Name: " & c_account

do shell script "echo " & quoted form of myoutput & "| cat>>/tmp/mailboxsize_" & c_date & ".txt"

set account_sum to 0

repeat with mb_i from 1 to count of every mailbox of account c_account

set c_mailbox_name to (name of mailbox mb_i of account c_account) as text

set mailbox_size_t to message size of every message of mailbox mb_i of account c_account

set mailbox_size to 0

repeat with s in mailbox_size_t

set mailbox_size to mailbox_size + s

end repeat

set account_sum to account_sum + mailbox_size

set mailbox_size to do shell script "echo 'scale=2; " & mailbox_size & "/1024/1024'|bc"

set myoutput to tab & c_mailbox_name & ": " & mailbox_size & " MB"

do shell script "echo " & quoted form of myoutput & "| cat>>/tmp/mailboxsize_" & c_date & ".txt"

end repeat

set account_sum to do shell script "echo 'scale=2; " & account_sum & "/1024/1024'|bc"

set myoutput to tab & "=================================="

do shell script "echo " & quoted form of myoutput & "| cat>>/tmp/mailboxsize_" & c_date & ".txt"

set myoutput to tab & "SUMME: " & account_sum & " MB"

do shell script "echo " & quoted form of myoutput & "| cat>>/tmp/mailboxsize_" & c_date & ".txt"

end repeat

end if

end tell


do shell script "open /tmp/mailboxsize_" & c_date & ".txt"

No Comments