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]