AppleScript-Code zu HTML

Hm, ich dachte ich hätte das Ding schon mal hier gepostet, kann es aber selber nicht mehr finden. Die CodeBoxes die ich hier und z.B. im AppleScript-Forum einbaue, erstelle ich über ein Skript, welches (ganz abartig) GUI-Skripting und Text-Edit verwendet, um den entsprechenden HTML-Code zu generieren. Auf diese Weise geht es aber recht schnell.
Dabei sind 2 Vorkehrungen zu treffen:

1. damit GUI-Skripting überhaupt funktioniert

In den Systemeinstellungen und Bedienungshilfe diesen Haken setzen:

2. Textedit soll html Dateien mit Inline-CSS abspeichern und neue Dokument als Richtext anlegen

Funktionsweise


Das Skript schnappt sich den Inhalt der Zwischenablage, öffnet TextEdit, fügt die Zwischenablage dort ein, speichert die Datei als HTML ab (GUI-Skripting, also selber keine Tastatur-Eingabe oder ähnliches dabei tätigen!) und zieht sich aus dieser dann den HTML-Code, verfrachtet diesen in einen entsprechenden div-container…. der Quellcode landet anschließen in der Zwischenablage

try

tell application “TextEdit”

activate

make new document

set n to name of window 1

set nn to my checkname_with_pdf_suffix((n & “.html”) as text, path to desktop, false)

tell application “System Events”

tell process “TextEdit”

delay 0.25

keystroke “v” using command down

delay 0.5

keystroke “s” using command down

delay 0.5

keystroke “d” using command down

delay 0.5

keystroke “Ohne Titel” using command down

delay 1

click pop up button 1 of group 1 of group 1 of sheet 1 of window n

delay 0.25

key code 125

key code 125

delay 0.25

keystroke return

if nnn then

set n to nn

delay 0.5

keystroke “a” using command down

delay 0.5

set the clipboard to nn

keystroke “v” using command down

end if

delay 1

keystroke return

delay 1

keystroke “w” using command down

end tell

end tell

end tell

tell application “Finder”

–set h to POSIX path of (selection as alias)

if n ends with “.html” then

set h to “/Users/hubi/Desktop/” & n

else

set h to “/Users/hubi/Desktop/” & n & “.html”

end if

end tell

if h ends with “.html” then

set t to do shell script “cat ” & quoted form of h

repeat with i from 1 to count of every paragraph of t

if paragraph i of t = “<body>” then

set t to paragraphs (i + 1) through ((count of every paragraph of t) – 2) of t

exit repeat

end if

end repeat

set the clipboard to “<div style=\”border: 1px solid #ccc; margin: 4px; padding: 4px; background: rgb(204, 204, 204) none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; width: 700px; max-width: 700px; max-height: 450px; overflow-x: auto; overflow-y: visible; font-size: 1.1em; color: rgb(0, 0, 0);-webkit-box-shadow:3px 3px 10px #666;-moz-box-shadow:3px 3px 10px #666;box-shadow:3px 3px 10px #666\”>” & t & “</div>” as text

do shell script “rm ” & quoted form of h

display_message(“body-contents in clipboard”, 1)

end if

on error msg

error msg

end try

on checkname_with_pdf_suffix(n, D, looped)

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 n to ((characters 1 through -6 of n) & ” 1″ & (characters -5 through -1 of n)) as text

checkname_with_pdf_suffix(n, D, true)

else

set tmp to (last word of ((characters 1 through -6 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 & (characters -5 through -1 of n)) as text

checkname_with_pdf_suffix(n, D, true)

end if

else

return n

end if

end checkname_with_pdf_suffix

on display_message(msgTXT, msgTimeout)

tell application “System Events”

set isRunning to ¬

(count of (every process whose name is “GrowlHelperApp”)) > 0

end tell

if isRunning = true then

tell application “GrowlHelperApp”

— Make a list of all the notification types 

— that this script will ever send:

set the allNotificationsList to ¬

{“Status”}

— 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 ¬

{“Status”}

— Register our script with growl.

— You can optionally (as here) set a default icon 

— for this script’s notifications.

register as application ¬

“Finder” all notifications allNotificationsList ¬

default notifications enabledNotificationsList ¬

icon of application “Finder”

Send a Notification…

notify with name ¬

“Status” title ¬

“Status” description ¬

msgTXT application name ¬

“Finder”

return true

end tell

else

activate

display dialog msgTXT giving up after msgTimeout

end if

end display_message

One thought on “AppleScript-Code zu HTML

  1. […] den Originalbeitrag weiterlesen: AppleScript-Code zu HTML at hubionmac.com Medien zum Thema   Medien by […]

Leave a Reply