Connect failed: Connection timed out

[GastForen Programmierung/Entwicklung AppleScript TextDatei aus TextEdit als PDF Drucken

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

TextDatei aus TextEdit als PDF Drucken

Anonym
Beiträge gesamt: 22827

22. Sep 2005, 08:54
Beitrag # 1 von 9
Bewertung:
(4261 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Guten Morgen

Ich benötige ein Script das mir .txt Dateien aus einem Hotfolder in TextEdit öffnet und als PDF in einen anderen Ordner Speichert. Und danach die .txt Datei löscht.
Mein bisheriges Script sieht so aus:


on adding folder items to this_folder after receiving added_items
 set watchfolder to this_folder as string
 repeat with x in added_items
  tell application "Finder"
   open file x
  end tell
  tell application "TextEdit"
   print document "report.txt" with properties "pdf"
  end tell
 end repeat
end adding folder items to



Das einzige was bisher aber funktioniert ist das er die Datei wenn diese in den gewählten Ordner fliegt in TextEdit Öffnet.
Hier komme ich nicht weiter. Freue mich über jede hilfe die ich bekommen kann :-)
X

TextDatei aus TextEdit als PDF Drucken

Hans Haesler
  
Beiträge gesamt: 5826

22. Sep 2005, 10:55
Beitrag # 2 von 9
Beitrag ID: #420206
Bewertung:
(4260 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo Yoschi147,

ich nehme an, dass Du Mac OS 10.4.x benutzest (denn unter Panther gibt es beim Überprüfen Deines
Scripts eine Fehlermeldung).

Das Drucken funktioniert nicht, weil der Befehl unvollständig ist. Es fehlt der Pfad, in welchen
die Datei gedruckt werden soll. Abgesehen davon: Woher hast Du den Zusatz 'with properties "pdf"'?
Laut Verzeichnis werden dort nur Angaben wie die Anzahl Kopien, Start- und Endseite usw. erwartet.

Es sieht also so aus, als ob das direkte Drucken in eine PDF-Datei (so wie es über den Druck-Dialog
möglich ist) nicht gescriptet werden kann. Ich werde aber nachforschen, ob es eine Lösung gibt.

Weitere Bemerkungen: Die Zeile 'set watchfolder to this_folder as string' stammt sehr wahrscheinlich
aus einem anderen Script. Die Variable 'watchfolder' wird nicht gebraucht. Und statt den Finder zu
bitten, dass er das Dokument öffnet, sollte direkt TextEdit eingespannt werden. Als Dokumentname
verwendest Du "report.txt", obwohl die Dokumente sicher nicht alle so heissen …

Gruss,
Hans


als Antwort auf: [#420205]

TextDatei aus TextEdit als PDF Drucken

Anonym
Beiträge gesamt: 22827

22. Sep 2005, 11:11
Beitrag # 3 von 9
Beitrag ID: #420207
Bewertung:
(4260 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Erstmal vielen Dank für deine Hilfe.

du hast recht ich verwende OSX Tiger
ja das mit dem Watchfolder hab ich aus einem anderen Script. (und wird in diesem Script nicht benötigt)
Die Dokumente heißen alle report.txt den der wird vorher vom Automator aus 2 Datein geschnitzt und immer als report.txt abgelegt.

Ich brauche nur irgendwie ne möglichkeit aus nem .txt Dokument automatisch nen PDF erstellen zu lassen. Das muß doch irgendwie möglich sein :-(


thx


als Antwort auf: [#420205]

TextDatei aus TextEdit als PDF Drucken

Anonym
Beiträge gesamt: 22827

22. Sep 2005, 11:19
Beitrag # 4 von 9
Beitrag ID: #420208
Bewertung:
(4260 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
nochmal ne dumme frage


Ich habe grad ein bißchen in den Standart Scripts von Tiger gewühlt und habe dort in dem Ordner Scripts\Printing Scripts zwei AppleScripts gefunden:

1. Convert To PDF

(*
Copyright © 2003 Apple Computer, Inc.

You may incorporate this Apple sample code into your program(s) without
restriction.  This Apple sample code has been provided "AS IS" and the
responsibility for its operation is yours.  You are not permitted to
redistribute this Apple sample code as "Apple sample code" after having
made changes.  If you're going to redistribute the code, we require
that you make it clear that the code was descended from Apple sample
code, but that you've made changes.
*)

property RadarProblem3258323IsFixed : false
property type_list : {"JPEG", "GIFf", "PICT", "TIFF", "PDF", "TEXT"}
property extension_list : {"jpg", "gif", "pct", "tif", "pdf", "rtf"}
--html is not currently handled

on run {}
 tell application "Finder"
  try
   set FinderSelection to the selection as alias list
  on error
   --Finder Scripting fails with one item (Radar problem 2741967)
   set FinderSelection to the selection
  end try
 end tell
 
 if RadarProblem3258323IsFixed then
  set FS to FinderSelection
  --Ideally, this list could be passed to the open handler
 else
  set FS to {}
  repeat with EachItem in FinderSelection
   copy EachItem as alias to end of FS
  end repeat
 end if
 
 set SelectionCount to number of FS -- count 
 if SelectionCount is 0 then
  set FS to userPicksFolder()
 else if the SelectionCount is 1 then
  set MyPath to path to me
  if MyPath is item 1 of FS then
   --If I'm a droplet then I was double-clicked
   set FS to userPicksFolder()
  end if
 else
  --I'm not a double-clicked droplet
 end if
 open FS
end run

on userPicksFolder()
 set these_items to {}
 set these_items to (choose file with prompt "Select a file to convert to PDF:" of type {"JPEG", "GIFf", "PICT", "TIFF", "TEXT", "RTF"}) as list
end userPicksFolder

on open these_items
 set thesefiles to {}
 set the item_info to {}
 repeat with i from 1 to the count of these_items
  set this_item to (item i of these_items)
  set the item_info to info for this_item
 
  if folder of the item_info is true then --if the item is a folder
   processFolder(this_item)
  else if ((folder of the item_info is false) and ¬
   (alias of the item_info is false)) and ¬
   (the file type of the item_info is in the type_list) or ¬
   ((the name extension of the item_info) is in the extension_list) then
   
   set theFilePath to (item i of these_items as string)
   set thePOSIXFilePath to POSIX path of theFilePath as string
   processFile(thePOSIXFilePath)
  end if
 end repeat
end open

--process folders
on processFolder(theFolder)
 set these_items to list folder theFolder without invisibles
 repeat with i from 1 to the count of these_items
  set this_item to alias ((theFolder as text) & (item i of these_items))
  set the item_info to info for this_item
  if folder of the item_info is true then
   processFolder(this_item)
  else if (alias of the item_info is false) and ¬
   ((the file type of the item_info is in the type_list) or ¬
    the name extension of the item_info is in the extension_list) then
   set theFilePath to (this_item as string)
   set thePOSIXFilePath to POSIX path of theFilePath as string
   processFile(thePOSIXFilePath)
  end if
 end repeat
end processFolder

on processFile(thePOSIXFileName)
 try
  set terminalCommand to ""
  set convertCommand to "/System/Library/Printers/Libraries/./convert "
  set newFileName to thePOSIXFileName & ".pdf"
  set terminalCommand to convertCommand & "-f " & "\"" & thePOSIXFileName & "\"" & " -o " & "\"" & newFileName & "\"" & " -j \"application/pdf\""
 
  do shell script terminalCommand
 end try
end processFile





und 2.  About Convert

set carriage_return to return as text

set message_A to "The Convert… scripts convert a file to PDF or PostSctript." & ¬
 carriage_return & carriage_return & ¬
 "To convert files in batch mode, open the appropriate script (/Library/Scripts/Printing Scripts) in ScriptEditor and save the script as an application. Then drag the files to be converted on to the new application." & ¬
 carriage_return & carriage_return & ¬
 "A script can also be easily open in Script Editor by holding down the Option Key while selecting that script in the Scripts menu."

display dialog message_A buttons {"OK"} default button 1 with icon note



kann mann mit denen nicht irgendwie was anfangen? Ich verstehe da leider zur zeit halt nur noch Banhof.

Da gäbs auch noch eins "Convert To PostScript.
Oder weiß vieleicht jemand ob das mit dem Automator geht?


als Antwort auf: [#420205]

TextDatei aus TextEdit als PDF Drucken

Hans Haesler
  
Beiträge gesamt: 5826

22. Sep 2005, 11:35
Beitrag # 5 von 9
Beitrag ID: #420209
Bewertung:
(4260 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo Yoschi147,

wie schon gesagt, ich werde nachforschen, kann dies aber frühestens im späteren Nachmittag tun.
Ja, auf den ersten Blick sieht es so aus, als ob das Script, welches Du gefunden hast, für
Deine Aufgabe benutzt weden kann.

Gruss, Hans


als Antwort auf: [#420205]

TextDatei aus TextEdit als PDF Drucken

Hans Haesler
  
Beiträge gesamt: 5826

22. Sep 2005, 16:46
Beitrag # 6 von 9
Beitrag ID: #420210
Bewertung:
(4260 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo Yoschi147,

und hier ist die Lösung. :-) Das Programm TextEdit wird nicht mehr verwendet, sondern der 'convert'-Befehl
des Systems, welcher mit 'do shell script' ausgeführt wird. Die entsprechenden Zeilen habe ich dem Script
von Apple entnommen und leicht abgewandelt, damit das Suffix ".txt" durch ".pdf" ersetzt wird.

Beim ersten Gebrauch wirst Du aufgefordert werden, einen Zielordner für die PDF-Dateien zu bestimmen.
Dieser Pfad wird in einer Textdatei im Ordner "Bibliothek/Preferences" gespeichert. Bei der zweiten Ausführung
wird dieser Pfad eingelesen und der Dialog erscheint erst wieder, wenn der Zielordner unauffindbar ist.
---
on adding folder items to sourceFolder after receiving itemList
   set targetPath to (path to preferences as Unicode text) & "targetPath.txt"
   try
      set targetFolder to read file targetPath as Unicode text
   on error
      with timeout of 300 seconds
         activate
         set targetFolder to (choose folder with prompt "Einen Zielordner für die PDF-Dateien wählen.") as Unicode text
      end timeout
      writePath(targetFolder)
   end try
   try
      targetFolder as alias
   on error
      with timeout of 300 seconds
         activate
         set targetFolder to (choose folder with prompt "Einen Zielordner für die PDF-Dateien wählen.") as Unicode text
      end timeout
      writePath(targetFolder)
   end try
   set targetFolder to POSIX path of targetFolder
   set sourceFolder to POSIX path of sourceFolder
   repeat with aFile in itemList
      tell application "Finder" to set curName to (name of file aFile)
      if curName ends with ".txt" then
         set fileName to text 1 thru -5 of curName
         try
            set terminalCommand to ""
            set convertCommand to "/System/Library/Printers/Libraries/./convert "
            set posixPath to (sourceFolder & curName) as Unicode text
            set newFilePath to (targetFolder & fileName & ".pdf") as Unicode text
            set terminalCommand to convertCommand & "-f " & "\"" & posixPath & "\"" & " -o " & "\"" & newFilePath & "\"" & " -j \"application/pdf\""
            do shell script terminalCommand
            tell application "Finder" to delete file aFile
         end try
      end if
   end repeat
end adding folder items to

on writePath(targetFolder)
   set targetPath to (path to preferences as Unicode text) & "targetPath.txt"
   try
      open for access file targetPath with write permission
      set eof of file targetPath to 0
      write targetFolder to file targetPath as Unicode text
      close access file targetPath
   on error
      try
         close access file targetPath
      end try
   end try
end writePath

---
Jetzt bleibt nur noch die Frage zu klären, wie das Problem mit all diesen gleichnamigen Dateien gelöst werden kann.

Gruss, Hans


als Antwort auf: [#420205]

TextDatei aus TextEdit als PDF Drucken

Anonym
Beiträge gesamt: 22827

23. Sep 2005, 08:56
Beitrag # 7 von 9
Beitrag ID: #420211
Bewertung:
(4260 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
VIelen Dank für deine Hilfe :-)

Klappt alles wunderbar. das mit den Dateinamen ist kein Problem da dieser Report ruhig ersetzt werden kann. Das einzige prob was ich habe ist das das PDF das erstellt wird jedesmal nur eingeschränkte benutzerrechte hat (nur admin dar Lesen und Schreiben) alle anderen User haben keine rechte.


als Antwort auf: [#420205]

TextDatei aus TextEdit als PDF Drucken

Hans Haesler
  
Beiträge gesamt: 5826

23. Sep 2005, 10:00
Beitrag # 8 von 9
Beitrag ID: #420212
Bewertung:
(4260 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo Yoschi147,

bitteschön!

Das Problem mit den Rechten kannst Du beheben, indem Du im Script die hier
farbig hervorgehobene Zeile einfügst:
---
do shell script terminalCommand
do shell script "chmod 777 " & newFilePath
tell application "Finder" to delete file aFile

---
Gruss, Hans


als Antwort auf: [#420205]

TextDatei aus TextEdit als PDF Drucken

Anonym
Beiträge gesamt: 22827

23. Sep 2005, 10:18
Beitrag # 9 von 9
Beitrag ID: #420213
Bewertung:
(4260 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Jepp klappt wunderbar


thx


als Antwort auf: [#420205]
X