[GastForen Programmierung/Entwicklung AppleScript Textexport aus Quark

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

Textexport aus Quark

Anonym
Beiträge gesamt: 22827

23. Dez 2004, 09:08
Beitrag # 1 von 5
Bewertung:
(1050 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
tell application "QuarkXPress™ 4.11"
tell document 1


  set allText to ""
  set countOfStories to count stories
  repeat with storyNum from 1 to countOfStories
  set allText to allText & contents of story storyNum & return & return
  end repeat --with textBoxNum from 1 to countOfTextBoxes


end tell --document 1
end tell --application "QuarkXPress™ 4.11"

set newFile to new file with prompt "Save extracted text as:"

set newFileRef to open for access newFile with write permission
write allText to newFileRef
close access newFileRef


Dieses Script habe irgendwo ausgegraben und soll den kompletten Text
eines QXP Dokuments exportieren.
Doch leider meldet der Parser einen Syntaxfehler in der Zeile set newFile.

Was fehlt denn da noch?

Gruss
Christoph
X

Textexport aus Quark

Hans Haesler
  
Beiträge gesamt: 5826

23. Dez 2004, 14:45
Beitrag # 2 von 5
Beitrag ID: #419283
Bewertung:
(1049 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo Christoph,

das 'new file' kenne ich nicht. Aber mit 'choose file name' funktioniert es.
Beachte bitte, dass ich die 'count stories' direkt als End-Parameter benutze und als
Zählervariable das gute, alte, kurze 'i'.

Das Schreiben der Datei muss unbedingt mit einem 'try'-Wrapper umgeben werden, damit man
bei einem Problem versuchen kann, die geöffnete Datei wieder zu schliessen.
---
tell document 1 of application "QuarkXPress 4.11"
    set allText to ""
    repeat with i from 1 to count stories
        set allText to allText & contents of story i & return & return
    end repeat
end tell

set newFile to (choose file name with prompt "Dateiname für den exportierten Text")
set newFileRef to open for access newFile with write permission
try
    write allText to newFileRef
    close access newFileRef
on error
    try
        close access newFileRef
    end try
end try

display dialog "Fertig." buttons "OK" default button 1 with icon 1 giving up after 1

---

Und hier eine Variante, welche die Datei in den Ordner schreibt, in welchem sich das XPress-Dokument
befindet. Man muss also nur den Namen der Datei eingeben und nicht mehr den Zielordner wählen.
---
tell document 1 of application "QuarkXPress 4.11"
    set docPath to (get file path) as string
    if docPath is "null" then
        display dialog "Bitte das Dokument zuerst sichern." buttons "OK" default button 1 with icon 0
        error number -128
    end if
    set allText to ""
    repeat with i from 1 to count stories
        set allText to allText & contents of story i & return & return
    end repeat
end tell

set AppleScript's text item delimiters to {":"}
set filePath to (text items 1 thru -2 of docPath) as string
set AppleScript's text item delimiters to {""}

set newFile to text returned of (display dialog "Dateiname für den exportierten Text" default answer "")

set txtPath to filePath & ":" & newFile & ".txt"
try
    open for access file txtPath with write permission
    set eof of file txtPath to 0
    write allText to file txtPath
    close access file txtPath
on error
    try
        close access file txtPath
    end try
end try

display dialog "Fertig." buttons "OK" default button 1 with icon 1 giving up after 1

---

Und zum Schluss noch ein Script, welches den Namen des XPress-Dokuments als Name für die Texdtdatei
übernimmt und das Suffix ".txt" anhängt.
---
tell document 1 of application "QuarkXPress 4.11"
    set docPath to (get file path) as string
    if docPath is "null" then
        display dialog "Bitte das Dokument zuerst sichern." buttons "OK" default button 1 with icon 0
        error number -128
    end if
    set allText to ""
    repeat with i from 1 to count stories
        set allText to allText & contents of story i & return & return
    end repeat
end tell

if character -4 of docPath is "." then
    set txtPath to text 1 thru -5 of docPath & ".txt"
else
    set txtPath to docPath & ".txt"
end if

try
    open for access file txtPath with write permission
    set eof of file txtPath to 0
    write allText to file txtPath
    close access file txtPath
on error
    try
        close access file txtPath
    end try
end try

display dialog "Fertig." buttons "OK" default button 1 with icon 1 giving up after 1

---

Hans Haesler <hsa@ringier.ch>


als Antwort auf: [#419282]

Textexport aus Quark

Anonym
Beiträge gesamt: 22827

23. Dez 2004, 15:26
Beitrag # 3 von 5
Beitrag ID: #419284
Bewertung:
(1049 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Vielen Dank, Hans.
Soviele Geschenke. :D
Funktioniert tadellos.

Gruss Christoph


als Antwort auf: [#419282]

Textexport aus Quark

Hans Haesler
  
Beiträge gesamt: 5826

23. Dez 2004, 19:41
Beitrag # 4 von 5
Beitrag ID: #419285
Bewertung:
(1049 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo Christoph,

bitteschön! :-) Ich konnte sie leider nicht schöner verpacken &#133;

Wenn Du mal alle drei ausprobiert haben wirst, dann teile uns bitte mit, für welche Version
Du Dich entschieden hast. Und aus welchen Gründen.

TIA (= thanks in advance = danke im voraus),
Hans


als Antwort auf: [#419282]

Textexport aus Quark

Anonym
Beiträge gesamt: 22827

23. Dez 2004, 20:31
Beitrag # 5 von 5
Beitrag ID: #419286
Bewertung:
(1049 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Ich habe mich für die bequemste Variante, also für Nummer 3 entschieden.
Da es doch mehrere Dokumente sind, muss man sich nicht unbedingt mit Speicherziel und Dateinamen aufhalten.

Aus den so gesammelten Textdaten zaubere ich mir dann mit Hilfe von PHP/MYSQL das Suchen und Ersetzen Apple-Script.
Aus den exportierten Texten wird zuvor eine Art Keyword-Liste erzeugt.
Also eine Liste aus allen verwendeten Worten im Quark Dukument.
Wobei jedes Wort nur einmal vorkommt. Das ereldige ich wiederum in DELPHI, da ich mich mit APS etwas schwer tue.

Man könnte zwar sicherlich alles mit APS lösen, aber so bin ich nun zufrieden.

Danke nochmal.

Christoph Weis


als Antwort auf: [#419282]
X