Re: tabs to spaces
Re: tabs to spaces
- Subject: Re: tabs to spaces
- From: Scott Haneda <email@hidden>
- Date: Sun, 30 Nov 2008 15:12:57 -0800
I am making some progress, but getting a little stuck, maybe someone
can assist me, I will comment out the AppleScript as best as I can,
and where I am stumped:
Here is my clipboard: (Tab separated)
dasj dhsahdwe dhasdhajks ewqhehwq dsajkdhas
e das dsaw das daswf
fjdk ewf jken dsajkw dskdw
hklt ewq vn1 daskcn daskw
set current_clipboard to (the clipboard)
-- Find the longest string length in chunk of data
set the_cells to words of current_clipboard
set longest_cell_length to 0
repeat with the_cell in the_cells
if ((length of the_cell) ≥ longest_cell_length) then
set longest_cell_length to (length of the_cell)
set answer to the_cell
end if
end repeat
display dialog "longeset string is: (" & longest_cell_length & ") " &
answer
-- So for this works, it iterates the data, and tells me the longest
-- sting in that data, which is a value I will need.
-- Here is where I am stuck, I need to iterate every word, and add the
padding
-- I want to add, but will need to return the entire data back out, as
one
-- chunk of data, and maintain the carriage returns or line feeds, or
whatever
-- endings the copied data may have.
-- Pad the results
set foo to ""
repeat with the_cell in the_cells
set foo to strPadLeft(the_cell, longest_cell_length, " ") & foo
end repeat
return foo
-- Pretty basic, takes input, and left pads an arbitrary string to it
up to
-- the value of length.
on strPadLeft(input, length, pad_char)
set strlen_of_input to (length of input)
set spaces_to_add to (length - strlen_of_input)
set result_string to ""
repeat spaces_to_add times
set result_string to result_string & pad_char
end repeat
return result_string & input
end strPadLeft
On Nov 30, 2008, at 2:04 PM, Scott Haneda wrote:
Hello, I have a client who I am trying to help out, they currently
copy out of Excel, paste into Entourage, which seems to convert tabs
to spaces, and then copy and paste that out back into Apple Mail.
I am looking for an AppleScript that will convert tabs to spaces. I
found one, that was written back in the OS 9 days, and kind of sort
of barely works. Seems much more complicated then I need.
I would say, the specs would be:
Split the entire pasteboard into items, so each tab separated item
is in an array, you can then find the string length of the longest
item.
Knowing the string length of the longest item, an application of
"string pad left" or "string pad right" with spaces as the
character, would make them all the same length.
A pop up would ask of you want left aligned, or right aligned.
A second pop up would ask, how many spaces each tab should be
converted to.
Since this is pasted into email, I think 72 chars wide would be the
max, but I would make no effort to do so, if the data is too wide,
that is not the goal of this app to solve.
I have a hard time wrapping my head around AppleScript, and am
tempted to use php or bash, and wrap that up in an Automator
action. Then, I can do it on my own, but I have a feeling that will
be a little slow, and this is just basic string manipulation. If
this ends up needing an OSAX of some form, I would probably go the
bash/php wrapper method.
Can anyone help me get started.
--
Scott
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden