Replace text within a repeat function?

Hello all,

I have written a script that works with Image-ExifInfo, a PERL module, that allows me to pull all my captions from photos from a specific directory along with filename and created date into a tab delimited file that gets placed on the desktop. In this script it repeats using the Image-ExifTool application on each file in that folder and then adds the results to the end of a list that is delimited by returns.

I was curious if before It gets put at the end of that list it could be searched for any return characters and have them replaced by just a space? I found a large function to find and replace text but was hoping for something smaller to run inline before my result gets added to the end of my list.

Let me know if you can help, thanks.

Hmm… if you don’t want to put in some lengthy replacing function, I think there are two possibilities:

a) Check MacScripter.net’s http://osaxen.com whether there is some Scripting Addition out there that provides a function to replace text

b) Modify the Perl Code that your AppleScript is calling to return the result with the linebreaks already replaced - unlike AppleScript, Perl has some very powerful text replacing facilities:

$x =~ s/\n/ /g;

This line, for example, would replace every linebreak in the string variable $x with a space. If you have any questions, lemme know… :slight_smile:

Regards,
danB

Model: iBook g3/800 14"
Browser: Safari 312.3.3
Operating System: Mac OS X (10.3.9)

What are my options for using applescript to replace each return character or linebreak with a string of text such as " – "?

Also wouldn’t I need to edit the PERL application that outputs the info as text to get it to output it without linebreaks, or can I just use another PERL command to take that returned text and edit it? I dont care if it is applescript or PERL re-formatting the text string before it is added to my list, I just need it done. Thanks.

The Satimage Scripting Additions include an effective find/replace function that should do exactly what you want within the confines of AppleScript.

http://www.satimage.fr/software/en/

Model: TiBook; Dual G4
Browser: Safari 416.12
Operating System: Mac OS X (10.4)

AppleScript’s text item delimiters are your friend, mrpunkin. :slight_smile:

to switch_returns from t to d
	set tid to text item delimiters
	set text item delimiters to d
	tell t's paragraphs to set t to beginning & ({""} & rest)
	set text item delimiters to tid
	t
end switch_returns

set demoText to "I dont care if it is
applescript or PERL
re-formatting the
text string before
it is added to my list
I just need it done"

switch_returns from demoText to " -- "

--> "I dont care if it is -- applescript or PERL -- re-formatting the -- text string before -- it is added to my list -- I just need it done"