• Apfeltalk ändert einen Teil seiner Allgemeinen Geschäftsbedingungen (AGB), das Löschen von Useraccounts betreffend.
    Näheres könnt Ihr hier nachlesen: AGB-Änderung
  • Was gibt es Schöneres als den Mai draußen in der Natur mit allen Sinnen zu genießen? Lasst uns teilhaben an Euren Erlebnissen und macht mit beim Thema des Monats Da blüht uns was! ---> Klick

VoodooPad -> Graphviz

Sarah Nyn

Kaiser Wilhelm
Registriert
02.06.07
Beiträge
177
Guten Tag,

Ich habe ein kleines Script geschrieben und poste es hier für den Fall, dass es jemanden interessiert. Es ist sehr unschön und laienhaft geschrieben und hat auch ein paar Fehler.

Es geht darum, die Links der Applikation VoodooPad (nicht der Lite Version, da diese kein AS unterstützt) graphisch darzustellen. Dazu habe ich das Tool Graphviz verwendet. Es funktioniert so etwa, allerdings nicht besonders gut. Verbesserungen sind natürlich willkommen, ich möchte aber niemanden dazu auffordern. Sollte aber jemand ein anderes Visualisierungsprogramm kennen, das vielleicht geeignet wäre oder sogar mit AppleScript angesprochen werden könnte, bitte ich darum, mir dies mitzuteilen.

Funktion:
- Exportiert aus dem geöffneten Dokument von VoodooPad die Links und stellt diese als Text in einer Form dar, die von Graphviz gelesen werden kann.
- Speichert eine .dot Datei mit den Informationen in home/scriptfiles/dot/ (wird bei jedem Durchgang überschrieben)
- öffnet diese anschliessend mit Graphviz (Graphviz.app muss sich im Programme-Verzeichnis befinden)

Blöderweise erkenne ich nicht die Links selbst, sondern lasse mir erst eine Liste mit allen Seiten von VoodooPad geben. Dann gehe ich den Inhalt aller Seiten durch und suche nach Seitennamen. Ziemlich umständlich, aber mir ist nichts besseres eingefallen. Je nach Umfang des Dokuments dauert das eine Weile, bei mir sind es schon ein paar Sekunden, obwohl ich VoodooPad noch nicht so lange verwende und mein Dokument noch nicht allzu gross ist. Ich werde wohl die Zeit in Kauf nehmen oder kleinere Dokumente verwenden. Mir ist aufgefallen, dass es viel länger dauert, wenn das Skript als Programm gespeichert und dann vom Finder aufgerufen wird, als wenn es im Skripteditor abgespielt wird. Weiss zufällig jemand, was ich falsch mache?

Fehler:
- Gross- und Kleinschreibung wird ignoriert und alles wird bei der Darstellung klein geschrieben
- Strings innerhalb von Wörtern werden auch als Link aufgefasst, also "Bestrafung" z.B. enthält "fun", also wird dies als Link zur Seite Fun erkannt, was in VoodooPad nicht so ist.
- Heisst eine Seite "a" und eine weitere "ab", so werden beim Text "ab" beide verlinkt. Bei VoodooPad wäre es nur ein Link zur Seite "ab".
- Links zu Dateien werden nicht erkannt
- to be continued...

Zudem ist die Darstellung von Dokumenten mit vielen Links ziemlich wirr und unkoordiniert. Auf Hierarchie wird nicht geachtet, oft ist die Positionierung unsinnig. Man kann bei den Layout-Einstellungen etwas herumspielen, um möglicherweise eine passendere Darstellung zu finden. Manchmal ist es aber leider so, dass durch eine kleine Änderung wieder alles anders aussieht und sich nichts mehr da befindet, wo es vorher war. Auch bleiben viele Darstellungsmöglichkeiten von Graphviz ungenutzt.

Trotz der vielen Mängel bin ich einigermassen zufrieden mit dem Resultat.

Vieles ist nur schlecht oder garnicht gelöst, was aber keinesfalls an einem der Programme liegt, sondern an mir. Ich bitte um Nachsicht. Im Anhang ist eine Beispielgrafik.

Dankeschön!

Grüsse,
iSarah


Code:
on run
	
	set AppleScript's text item delimiters to ""
	set homepath to path to home folder as text
	set dotfile to homepath & "scriptfiles:dot:voodoodot.dot"
	tell application "Finder"
		try
			make new folder at ((home as text) & "scriptfiles:") with properties {name:"dot"}
		end try
		try
			delete file dotfile
		end try
	end tell
	
	tell application "VoodooPad"
		
		set number_of_pages to the number of pages of document 1
		set pagelist to {}
		set dotfile_refn to open for access file ¬
			dotfile with write permission
		
		write "digraph untitled {" & return to dotfile_refn
		
		repeat with i from number_of_pages to 1 by -1
			set the beginning of pagelist to name of page i of document 1 as text
		end repeat
		
		repeat with x from number_of_pages to 1 by -1
			set pagecontent to (text of page (item x of pagelist as text) of document 1) as string
			repeat with y from number_of_pages to 1 by -1
				if pagecontent contains item y of pagelist and x is not y then
					write "\"" & item x of pagelist & "\"->\"" & item y of pagelist & "\";" & return to dotfile_refn
				end if
			end repeat
		end repeat
		
		write "}" & return to dotfile_refn
		
		close access dotfile_refn
		
		tell application "Finder"
			open document file dotfile using application file "Graphviz.app" of folder "Applications" of startup disk
		end tell
		
		set AppleScript's text item delimiters to return
		
	end tell
	
end run
 

Anhänge

  • voodoodot.jpg
    voodoodot.jpg
    34,3 KB · Aufrufe: 146
Zuletzt bearbeitet:

Sarah Nyn

Kaiser Wilhelm
Registriert
02.06.07
Beiträge
177
Kleines Update. Keine Dateien im Papierkorb mehr. So wird auch die Darstellung in Graphviz aktuallisiert und es gibt nicht immer ein neues Fenster. Und eine Liste mit zu ignorierenden Seiten (kann gleich am Anfang des Scripts gesetzt werden).

Code:
on run 
    
   set ignorelist to {"put", "your", "pagenames", "which will be ignored","here"} 
   set AppleScript's text item delimiters to "" 
   set homepath to path to home folder as text 
   set dotfile to homepath & "scriptfiles:voodoodot2.dot" 
   tell application "Finder" 
      try 
         make new folder at ((home as text) & "scriptfiles:") with properties {name:"dot"} 
      end try 
   end tell 
    
   tell application "VoodooPad" 
       
      set number_of_pages to the number of pages of document 1 
      set pagelist to {} 
      set dotfile_refn to open for access file ¬ 
         dotfile with write permission 
       
      write "digraph untitled {" & return to dotfile_refn 
       
      repeat with i from number_of_pages to 1 by -1 
         set the beginning of pagelist to name of page i of document 1 as text 
      end repeat 
       
      repeat with x from number_of_pages to 1 by -1 
         set pagecontent to (text of page (item x of pagelist as text) of document 1) as string 
         repeat with y from number_of_pages to 1 by -1 
            if pagecontent contains item y of pagelist and x is not y and ignorelist does not contain item x of pagelist and ignorelist does not contain item y of pagelist then 
               write "\"" & item x of pagelist & "\"->\"" & item y of pagelist & "\";" & return to dotfile_refn 
            end if 
         end repeat 
      end repeat 
       
      write "}" & return to dotfile_refn 
       
      close access dotfile_refn 
       
      tell application "Finder" 
         open document file dotfile using application file "Graphviz.app" of folder "Applications" of startup disk 
      end tell 
       
      set AppleScript's text item delimiters to return 
       
   end tell 
    
end run