Ich muss mir immer wieder Daten aus Dokumenten ziehen, die so eigentlich nicht zu parsen sind. Bestes Beispielt war heute eine .doc-Datei, die einen Zeitplan beinhaltete und dieses Word-Konstrukt sollte nun in eine Datenbank eingefügt werden.
Kurz, das automatisch einzulesen war utopisch und jedes Feld nun via Copy&Paste zu befüllen kostet echt Zeit... Nun, ich bin zu einem Kompromiss gekommen, der mit das Leben in Zukunft auch etwas leichter machen:
Das Skript überwacht einmal gestartet die Zwischenablage. Am Anfang kann man noch eingeben wieviele Spalten die Tabelle haben soll und von da an wird jeder neue Inhalt in der Zischenablage zur Tabelle hinzugefügt. Tabelle heißt in diesem Fall eine tab-separierte Textdatei. Damit man beim Kopieren auch etwas Feedback erhält, wird jede Aktion von einem Ton begleitet und zudem sieht man in einem Terminal-Fenster, wie die Text-Datei anwächst...
Zu theoretisch? Ok, hier ein
und natürlich der Quellcode:
#Clipboard to Data Table 2016-08-19 © hubionmac.com
#Copies the clipboard contents to a text file, to make tables
# script ends as soon as you have the string "ende" in you clipboard
##Settings
set data_file_name to "clipboard_data_" & (do shell script "date '+%s'" & ".txt")
set columcount to (text returned of (display dialog "Count of Data Columns" default answer 2)) as integer
do shell script "touch ~/Desktop/" & quoted form of data_file_name
tell application "Finder" to set data_file to ((item data_file_name of desktop) as alias) as string
#show what happens to the file while the script is adding data
tell application "Terminal"
do script "tail -f ~/Desktop/" & quoted form of data_file_name
end tell
set ccb to the clipboard
set column_pointer to 0
set theline to {}
#### OMG repeat for ever!!! ;-)
repeat until 1 is 0
delay 1
if ccb as text ≠ (get the clipboard) as text then
set ccb to the clipboard as text
##remove newline characters from clipboard
set tmp to my replace_chars(ccb, "\n", "")
set tmp to my replace_chars(tmp, "\r", "")
set theline to theline & {tmp}
#play some feedback sound
do shell script "afplay /System/Library/Sounds/Tink.aiff"
if ccb is "ende" then
# when the clipboard = ende then quit the script
say "ende"
exit repeat
else
set column_pointer to column_pointer + 1
# when the line is full of data, write it to file and start over
if column_pointer = columcount then
##join theline to tap delimited line
set AppleScript's text item delimiters to tab
set theline to theline as text
set AppleScript's text item delimiters to ""
##write theline to file
my write_to_file(theline & "\n", data_file, true)
do shell script "afplay /System/Library/Sounds/Blow.aiff"
## reset vars for next run
set column_pointer to 0
set theline to {}
end if
end if
end if
end repeat
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
on write_to_file(this_data, target_file, append_data)
##slightly tweaked routine from http://www.macosxautomation.com/applescript/sbrt/sbrt-09.html which now writes utf-8 text files =)
try
set the target_file to the target_file as string
set the open_target_file to open for access file target_file with write permission
if append_data is false then set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof as «class utf8»
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file
Ich musste mich leider von meinem alten Webhoster verabeschieden. In Zeiten von Let's Encrypt noch für eine kleine Web-Präsenz für SSL-Verschlüsselung zu zahlen, wollte ich einfach nicht einsehen.
Ich bin nun zu netcup gewechselt und bin, abgesehen vom Support eigentlich zufrieden. Es nervt mich ein bischen, dass ich die Wordpress-App (eine für eine andere Domain) nicht an Laufen bekomme und mir der Support nichts weiter zu sagen hat, als dass sie für eine Dritthersteller-Software wie Wordpress keinen Support übernehmen könnne. Eine coole Ausrede, wenn doch eigentlich alles auf dem Webspace nur Dritthersteller-Software sein kann ;-)
Egal, ich habe mich damit arangiert, zumal ich die Haupt-Seiten eh mit Grav realisere. Der Rest ist ok, das Packoffice ist etwas langsam und Mail unterstütz auch kein Push mehr... NERV! Egal, für die nächsten 2 Jahre bin ich erst mal hier, den Umzugsstress gebe ich mir nicht mehr so schnell wieder.
Aber für die Mail-Problematik habe ich eine schöne Lösung gefunden. Mailbox.org bietet mir für schlanke 12 Euro im Jahr einen sauper verschlüsselte Mailbox und ich kann auch Mails über meine eigene Domain erhalten und direkt verschicken. So ist Netcup jetzt raus aus dem Mail-Verkehr und zudem kann ich meine Adressen und Termine auch über Mailbox sicher abwickeln, also sind Google und iCloud auch aussen vor.
Fazit des ganzen.
- Sobald mein alter Provider vielleicht doch mal für mich kostenlose Let's Encryp-Verschlüsselung unterstützt, bin ich sofort wieder bei ihm.
- Netcup ist schön günstig und reicht vollkommen aus, solange man nix vom Support haben möchte
- mailbox.org ROCKT!
Tja, jetzt ist es mal wieder soweit. Seit fast einem Jahr habe ich auf der Seite so gut wie gar nichts gemacht und logge mich dann ein und sehe, dass sich zahllose Updates u.a auch kritischer Natur in der Warteschleife befinden.
Ich habe nun schon länger damit geliebäugelt, die Seit auf ein anderes CMS umzustellen und Wordpress endlich eine Abfuhr zu erteilen. Und jetzt ist es soweit. GRAV ist nun das neue CMS hinter dieser Seite. Schlank, schnell und doch ziemlich mächtig. Mal sehen, wann ich den Nerv finde auch mal ein schönes Theme zu bauen ;-)
Ich habe seit 2007 eine recht überschaubare Sammlung von 300 Postings auf der Wordpress-Seite. Diese werde ich leider von Hand migrieren müssen, da ich auch auf Grund von Wordpress einiges an custom-code in den einzelnen Postings einbauen musste. Damit ist dann nach der kompletten Umstellung aber hoffentlich Schluss und sauberer Markdown-Code ist dann die Basis für alle Postings die da noch kommen mögen ;-)
Ich lasse die alte Seite aber nach wie vor online... werde nur die comments schließen und von der Startseite nun auf Grav umleiten =)
Die Idee war vor fast 9 Jahren irgendwie Emails zu Archivieren.. (ich persönlich habe einfach ein riesiges Mail-Postfach auf meinem Synology-NAS, in dass jedes Jahr die alten Emails wandern).
Nun dieses Skript pfuscht etwas (öffnet den Druck-Dialog über den Keyboard-Shortcut) und druckt die Email das PDF aus.
Die Anhänge einer Email werden kurz im Download-Ordner gepspeichert (Sicherheitsvorgabe von OSX) und dann in den Unterordner der Nachricht ~/Desktop/mail_archiv
verschoben.
Achtung: Auf Grund der Tatsache, dass das Script Tastatur-Befehler ausführen muss, um zu funktionieren, muss die Anwendung die das Script ausführt die entsprechenden Rechte für Bedienungshilfen erhalten.
-- Save Mail as PDF and it's attachments to folder
-- Created by hubionmac (22.03.2010) requested by Udo
-- Update by hubionmac (09.01.2019)
-- - works now with 10.13.6
-- - the name of the outputfolder my contain the time and no just the date (see variable showtimeinfoldername)
-- - checkname-function updated so it works with suffixes > 3 characters
-- - Save Attachment into any other folder than downloads does not work out of the box with newer OSX, so first save inside downloads (subfolders are allowed) and then move it to it's final destination ;-)
global frontmost_message_viewer
--this is the posix (unix) path of the folder you would like to store the messages in
--#####settings
set showtimeinfoldername to true
--#####settings
tell application "Finder" to set mymailboxpath to POSIX path of ((desktop) as alias) & "mail_archiv/"
tell application "Mail"
set myselection to my check_message_viewer_and_return_selection()
--works only with one selected message for many reasons...
if (count of myselection) = 1 then
repeat with currentMail in myselection
set currentSender to my (getEmail(sender of currentMail))
set currentDateSent to my getDatestring(date sent of currentMail, showtimeinfoldername)
set currentSubject to my replace_chars(my replace_chars(subject of currentMail, ":", "-"), "/", ":")
--Doppelpunkte kommen bei Dateinamen nicht so gut
set currentFolder2Store to mymailboxpath & currentDateSent & " " & currentSender & " " & currentSubject & "/" as string
my create_messagefolder(currentFolder2Store)
try
do shell script "mkdir ~/downloads/tmp_mail_downloads"
end try
repeat with a in (every mail attachment of currentMail)
set current_a_name to name of a
set current_a_name to my checkname_with_pdf_suffix(current_a_name, path to downloads folder, false)
save a in ((((path to downloads folder) as string) & "tmp_mail_downloads:" & current_a_name) as string)
do shell script "mv ~/downloads/tmp_mail_downloads/" & quoted form of current_a_name & " " & quoted form of currentFolder2Store
end repeat
set desktop_pdf_name to my checkname_with_pdf_suffix("1.pdf", path to desktop, false)
set the clipboard to desktop_pdf_name
my print_current_mail_as_pdf()
repeat until (index of window of frontmost_message_viewer) is 1
delay 1
end repeat
my move_desktop_pdf(desktop_pdf_name, currentFolder2Store)
--open destination folder in finder ( did it really work? YES!! =))
do shell script "open " & quoted form of currentFolder2Store
end repeat
else
error "Sorry, ich kann zur Zeit nur mit einer ausgewählten Email hantieren"
end if
end tell
to move_desktop_pdf(desktop_pdf_name, currentFolder2Store)
--used to move the printed pdf to it's final destination
set finalname to checkname_with_pdf_suffix("__message.pdf", (POSIX file currentFolder2Store) as alias, false)
try
tell application "Finder" to do shell script "mv " & POSIX path of ((desktop) as alias) & quoted form of desktop_pdf_name & " " & quoted form of currentFolder2Store & quoted form of finalname
on error msg
error "Fehler beim Bewegen der gedruckten Nachricht: " & msg as text
end try
end move_desktop_pdf
to getEmail(mailstring)
-- if an email contains the senders name like "Mr.Bla <bla@bla.com>" then returns just the email not leaves the name
if mailstring contains "<" then
return (characters ((offset of "<" in mailstring) + 1) through ((offset of ">" in mailstring) - 1) of mailstring) as text
else
return mailstring
end if
end getEmail
to getDatestring(thedate, withtime)
--format a date to a string like 2010-03-22
set monthnum to characters -2 through -1 of ("0" & ((month of thedate) as integer)) as text
set daynum to characters -2 through -1 of ("0" & ((day of thedate) as integer)) as text
set yearnum to year of the thedate
set hournum to characters -2 through -1 of ("0" & ((hours of thedate) as integer)) as text
set minutnum to characters -2 through -1 of ("0" & ((hours of thedate) as integer)) as text
if withtime is true then
return yearnum & "-" & monthnum & "-" & daynum & " " & hournum & "-" & minutnum as text
else
return yearnum & "-" & monthnum & "-" & daynum as text
end if
end getDatestring
to create_messagefolder(thepath_posix)
--I love mkdir -p, simple, short, easy to use
try
do shell script "mkdir -p " & quoted form of thepath_posix
on error msg
error msg
end try
end create_messagefolder
to replace_chars(this_text, search_string, replacement_string)
--this replaces characters
--used for folder and filenames, since a : must not be used for that
if this_text contains the search_string then
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 ""
end if
return this_text
end replace_chars
to checkname_with_pdf_suffix(n, D, looped)
--check if filename exists in D
-- so if "A File.pdf" exists it names it "A File 1.pdf","A File 2.pdf",...
tell application "Finder"
set thefiles to name of every item of (D as alias)
end tell
if thefiles contains n then
if looped = false then
set AppleScript's text item delimiters to "."
set suffix to text item -1 of n
set n to text items 1 through -2 of n
set n to n as string
set AppleScript's text item delimiters to ""
set n to n & " 1." & suffix as string
my checkname_with_pdf_suffix(n, D, true)
else
set AppleScript's text item delimiters to "."
set suffix to text item -1 of n
set n to text items 1 through -2 of n
set n to n as string
set AppleScript's text item delimiters to ""
set tmp to ((last word of n as text) as integer)
set tmpcount to (count of characters of (tmp as text)) + 5
set tmp to tmp + 1
set n to ((characters 1 through (-1 * tmpcount) of n) & tmp & "." & suffix) as text
my checkname_with_pdf_suffix(n, D, true)
end if
else
return n
end if
end checkname_with_pdf_suffix
to print_current_mail_as_pdf()
--hopefully works on every mac in every language =)
-- GUI-Scripting is not the best way, but somehow the only way at the moment :-/
tell application "Mail"
activate
tell application "System Events"
tell process "Mail"
keystroke "p" using command down
set p to "false"
repeat with i from 1 to 10
if (count of every sheet of window 1) > 0 then
set p to "ready"
exit repeat
end if
delay 1
end repeat
if p = "ready" then
click menu button 1 of sheet 1 of window 1
delay 0.25
key code 125
key code 125
delay 0.25
keystroke return
delay 1
click text field 1 of sheet 1 of sheet 1 of window 1
--click text field 1 of window 1
keystroke "a" using command down
delay 0.25
keystroke "v" using command down
delay 0.25
keystroke "d" using command down
keystroke return
else
error "timeout"
end if
end tell
end tell
end tell
end print_current_mail_as_pdf
to check_message_viewer_and_return_selection()
-- check if frontmost window is a message viewer, otherwhise tell the user to RTFM!... wait there is no manual... don't care error change user!
tell application "Mail"
set frontmost_message_viewer to {}
repeat with i from 1 to count of every message viewer
if index of window of message viewer i = 1 then
set frontmost_message_viewer to message viewer i
exit repeat
end if
end repeat
if frontmost_message_viewer = {} then
error "Ist ja gar kein Message Viewer im Vordergrund, so kann ich einfach nicht arbeiten!"
else
return selection
end if
end tell
end check_message_viewer_and_return_selection
delay 5
tell application "Finder" to close window 1```
Ein kleines JavaScript Bookmark, mit dem die Seite stets hoch und runter scrollt....
javascript:timeout(30000);function%20timeout(t)%20{$(%22html,%20body%22).animate({%20scrollTop:%20$(%22html,%20body%22).height()%20},%20t);$(%22html,%20body%22).animate({%20scrollTop:%200%20},%202000);window.setTimeout(function%20()%20{$(%22html,%20body%22).animate({%20scrollTop:%20$(%22html,%20body%22).height()%20},%20t);$(%22html,%20body%22).animate({%20scrollTop:%200%20},%202000);timeout(t);},%20t+3000);}