Hi
I need a little assistance here. I am new to applescript, so please bear with me.
I have data copied into my clipboard that I would like to access and edit within my applescript, then write to a file in a plain text format. The data is 3 columns wide and can be anywhere from 40 to 4000 rows long.
I would like to completely remove the first 2 columns and the first 10 rows of the data every time the script is run, leaving me with one column of data written in a plain text file. Nothing else.
I currently have a script written that utilizes Microsoft Excel to do this exact procedure, but due to licensing issues, etc., I need for this to be handled within the applescript or an applescript studio application. Is this at all possible? Please help!
set rowsToDelete to 5
set columnDelimiter to tab
--> use here something as "set sampleData to (the clipboard)"
set sampleData to ¬
"a b c
d e f
g h i
j k l
m n o
1 2 3
4 5 6
7 8 9"
set finalText to {}
set prevtids to AppleScript's text item delimiters
set AppleScript's text item delimiters to columnDelimiter
repeat with i in paragraphs (rowsToDelete + 1) thru -1 of sampleData --> process anything except for 5 first rows
set finalText's end to item 3 of i's text items
end repeat
set AppleScript's text item delimiters to prevtids
--> coerce clean list "finalText" to string, using "return" as delimiter
set prevtids to AppleScript's text item delimiters
set AppleScript's text item delimiters to return
set finalText to finalText as text
set AppleScript's text item delimiters to prevtids
--> write to file
set fRef to (open for access (choose file name default name "output.txt") with write permission)
set eof of fRef to 0
write (finalText as text) to fRef
close access fRef
beep 2
After playing with it, it seems like its almost there, but when the script gets to a line of data with no information in the 3rd cell over, it gives me an error.
I assume this is beause it’s an empty cell. It’s happening at the last row of data because it’s the only line with no data in that 3rd cell over. Does this make sense?
How can I tell the script to stop the repeat process once it hits an empty cell in that 3rd column over?