String confused with Items?? what am I doing wrong?

Greetings

String confused with Items?? what am I doing wrong?

It is supposed to return in the log file something like…
<the date & time> “** * * * * * * * * * * * * * * * * * **”

To run the script, I think you need a folder called “backup” on the desktop.

-- THE START
my logit(decorate("*", 0), "")

--Define log
to logit(log_string, log_file)
	--Write to log file
	if log_file is "" then
		set log_file to "Backup History"
	end if
	do shell script ¬
		"echo `date '+%Y-%m-%d %T: '`\"" & log_string & ¬
		"\" >> " & (quoted form of POSIX path of (path to desktop)) & "backup/" & quoted form of log_file & ".log"
end logit

to decorate(c1, x)
	if x is 0 then set x to 9
	set mystring to ""
	repeat with i from 1 to x
		set mystring to (mystring & c1 as string)
		set c1 to (c1 & space as string)
	end repeat
	repeat with i from 1 to x
		set mystring to (mystring & c1 as string)
		set c1 to (characters 1 thru -2 of c1 as string) -- *** I guess this is the offensive line ***
	end repeat
	set mystring to (mystring & c1 as string)
	set mystring to (mystring & c1 as string)
	return mystring
end decorate

…what I get is the first half of the string then a great mass of commas and occasional spaces and asterisks…

It seems like variable c1 turns into a list at some point…???

This is part of a backup script I wrote recently after three days of research on this forum. : )

Any help or advice would be appreciated.

Kind regards, nodrog.

Model: Mac mini
AppleScript: no idea
Browser: Safari 533.22.3
Operating System: Mac OS X (10.5)

Hi nodrog,

Right off the bat, it seems like there must be a better way to do what you’re trying to do. Don’t have enough info yet.

gl,
kel

Hi Kel1

Thanks for the prompt reply.

The decorate function is just simple way to easily spot the end (or beginning) of a lengthy process in the log file.

Yeah, I could have just used a straight text string, but I am wanting to understand the way strings of text can be manipulated. It is a learning tool for me also.

What more info would you like?

e.g. This is what I get…
2014-05-21 10:26:34: ** * * * * * * * * , , , , , , , , , , , , , , , ,, , , , , , , ,, , , , , , , ,, , , , , , , ,, , , , , , , ,, , , , , , , ,, , , , , , , ,, , , , , , , ,, , , , , , , ,

Kind regards, nodrog.

…also

An easier method might be to simply reverse the first part of the string, however, I’d like to know what is causing the output looking like it does…?

Kind regards, nodrog.

Hi. I am more bewildered by the clarification than the original post. Your code has duplicate lines and featured unnecessary coercions; it also confused characters”which are list items”for the text class. This fixes the first part:

to decorate(c1, x)
	if x is 0 then set x to 9
	set mystring to ""
	repeat with i from 1 to x
		set mystring to (mystring & c1)
		set c1 to (c1 & space)
	end repeat	
	repeat with i from 1 to x
		set mystring to (mystring & c1)
		set c1 to (c1's text 1 thru -2)
	end repeat
	set mystring to (mystring & c1)
end decorate

Hi Marc

Thank you for your reply.

My apologies for any added confusion. (Including this reply).

When I first wrote the decorate function, it worked on my computer (or seemed to evidently). I then copied onto a later version of computer and it started to fail. When I copied it back it also failed (I might be going crazy also).

The repeated lines were to get the desired result as it ended slightly truncated at first writing.

I was getting <the date & time> "** * * * * * * * * * * * * * * * * * "

…instead of <the date & time> “** * * * * * * * * * * * * * * * * * **”

OK, I will try your suggestion and get back to you.

Kind regards, nodrog

Hi Marc & others

Ok, this works…

to decorate(c1, x)
	if x is 0 then set x to 9
	set mystring to ""
	repeat with i from 1 to x
		set mystring to (mystring & c1)
		set c1 to (c1 & space)
	end repeat
	repeat with i from 1 to x
		set mystring to (mystring & c1)
		set c1 to (c1's text 1 thru -2)
	end repeat
	set mystring to (mystring & c1)
	set mystring to (mystring & c1) -- repeated to get the last character
end decorate

btw: The unnecessary coercions were part of a feeble attempt to remove the commas.

Your version is great except I get:

The repeated line gives me the correct result:

I am very happy.

I totally did not know and was and am confused that characters”are list items”for the text class.

Thanks to those who took the trouble to consider my problem, small as it was.

Special thanks to Marc who gave the working solution.

Kind regards, nodrog.

Hi Marc

In deference to your point about repeated lines, I make this correction…

to decorate(c1, x)
	if x is 0 then set x to 9
	set mystring to ""
	repeat with i from 1 to x
		set mystring to (mystring & c1)
		set c1 to (c1 & space)
	end repeat
	repeat with i from 1 to x
		set mystring to (mystring & c1)
		set c1 to (c1's text 1 thru -2)
	end repeat
	set mystring to (mystring & c1 & c1) -- no need to repeat the whole line to add the last character
end decorate

Thanks again.

Kind regards, nodrog.