Applescript probleem
1 april 2005 - 17:05   
geplaatst door: Skilgannon
Ik zit met een probleempje. Ik moet in een txt-file alle $-tekens aanpassen in een @-teken. Nu dat gaat wel met een find & replace maar het gaat hier om honderden files wat dus een enorm werkje zou zijn. Nu ik ben begonnen met een applescriptje maar het wil niet vlotten, kan iemand mij hiermee helpen

Thx
Skilgannon

One of the Lost Ones
Applescript probleem
1 april 2005 - 17:09    reactie #1
geplaatst door: Robert
Ik heb even snel met Google gezocht en de 2e (!) link gaf dit resultaat: http://macscripter.net/faq/miscellaneous.php?id=10

Volgens mij zou je daar wat aan moeten hebben...

Klik hier voor informatie over het onder de aandacht brengen van producten of diensten op MacFreak.
Applescript probleem
1 april 2005 - 17:30    reactie #2
geplaatst door: Skilgannon
Neen die doet het niet.

ff wat meer duidelijkheid, in de txt-file staan $-tekens maar direct daarna gevolgd door een benaming (bvb $0123price, $0124periode, $0125stoptext) en het is daarvoor dat ik de $-tekens moet vervangen naar een @, het is dus niet zo dat het $-teken als een enkel caracter staat maar steeds in een benaming. Maar dat scriptje doet het niet, ofwel snap ik het niet volledig.

One of the Lost Ones
Applescript probleem
1 april 2005 - 17:50    reactie #3
geplaatst door: zonapple
Staan er ook $'s in die niet vervangen moeten worden ?

Zoniet, dan vervangt dit script alle $ door @.

on open these_files
set aantal to the count of these_files
repeat with counter from 1 to aantal
set this_file to item counter of these_files
if the name extension of (info for this_file) is "txt" then
set file_text to read this_file
set new_file_text to replace_chars(file_text, "$", "@")
write_to_file(new_file_text, this_file, false)
end if
end repeat
end open

on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars


on write_to_file(this_data, target_file, append_data)
try
set the target_file to the target_file as text
set the open_target_file to ¬
open for access file target_file with write permission
if append_data is false then ¬
set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file

Het grootste werk wordt verricht door twee handlers die ik van apple's site heb geplukt. Let wel op: dit script past de originele bestanden aan, dus voor het geval er iets mis gaat zou ik eerst even een backup maken van je teksten. Ik heb het namelijk maar met twee tekstbestandjes getest maar wie weet wat er bij 600 gebeurdÂ…
Kies bij het bewaren voor 'Programma' dan wordt het vanzelf een droplet waar de bestanden op kunt slepen.
Veel succes.

(Bewerkt door zonapple om 18:20, 1-04-2005)

There's 10 types of people in this world, those who understand binary and those who don't.