AppleScript Text ersetzen & Datei abspeichern

MilchKaffee

MilchKaffee

Aktives Mitglied
Thread Starter
Dabei seit
19.01.2006
Beiträge
797
Reaktionspunkte
3
Hallo,

ich habe ein Applescript geschrieben, welches eine Textdatei in Textedit aufruft und darin alle Kommata gegen Semikola austauschen soll. Zusätzlich soll es auch alle Anführungsstriche rauslöschen.

Das Ganze sieht so aus:

PHP:
tell application "Finder"
	activate
	open document file "test.txt" of folder "Desktop" of folder "userx" of folder "Users" of startup disk
	tell application "TextEdit"
		set test_str to text of document 1
		set AppleScript's text item delimiters to ","
		set test_items to text items of test_str
		set AppleScript's text item delimiters to ";"
		set final_str to test_items as text
		set text of document 1 to final_str
	end tell
	
	tell application "TextEdit"
		set test_str to text of document 1
		set AppleScript's text item delimiters to "\""
		set test_items to text items of test_str
		set AppleScript's text item delimiters to ""
		set final_str to test_items as text
		set text of document 1 to final_str
	end tell
	
end tell

Relativ easy also.

Aber: Wie realisiert man das autoamtische Abspeichern der Datei "test.txt" via Script und wie schliesst man Textedit wieder?

Danke für Hilfe!
 
Aber: Wie realisiert man das autoamtische Abspeichern der Datei "test.txt" via Script und wie schliesst man Textedit wieder?
PHP:
tell application "TextEdit"
close document 1 saving yes
end tell
Good scripting
Farid
 
Dankschee!!!
 
Fürs Terminal hätte ich da auch 'ne simple Lösung:

sed 's|,|;|g' /Pfad/zur/Datei



- sed ist das Programm
- das 's' bedeutet "substitute"
- dann das (,) was durch etwas anderes (;) ersetzt werden soll
- das 'g' steht für "global", sprich dem inhalt der gesamten datei
- die dann am ende angegeben wird
 
Zurück
Oben Unten