text parsing - Applescript: Break a set of lines into blocks based on a condition -


i have automator service uploading images , returning urls text editor. works well, there's want improve:

when workflow starts, automator images in folder , upload them ftp server. returns result below:

("http://url/0530/pic01/pic-01.jpg", "http://url/0530/pic01/pic-02.jpg", "http://url/0530/pic01/pic-03.jpg", "http://url/0530/pic01/pic-04.jpg", "http://url/0530/pic02/pic-01.jpg", "http://url/0530/pic02/pic-02.jpg", "http://url/0530/pic02/pic-03.jpg", "http://url/0530/pic02/pic-04.jpg", "http://url/0530/pic03/pic-01.jpg", "http://url/0530/pic03/pic-02.jpg", "http://url/0530/pic03/pic-03.jpg", "http://url/0530/pic03/pic-04.jpg") 

and workflow gets these strings , puts them in new text document.
finally, here result in text editor:

http://url/0530/pic01/pic-01.jpg  http://url/0530/pic01/pic-02.jpg http://url/0530/pic01/pic-03.jpg http://url/0530/pic01/pic-04.jpg http://url/0530/pic02/pic-01.jpg http://url/0530/pic02/pic-02.jpg http://url/0530/pic02/pic-03.jpg http://url/0530/pic02/pic-04.jpg http://url/0530/pic03/pic-01.jpg http://url/0530/pic03/pic-02.jpg http://url/0530/pic03/pic-03.jpg http://url/0530/pic03/pic-04.jpg 

but want be:

http://url/0530/pic01/pic-01.jpg  http://url/0530/pic01/pic-02.jpg http://url/0530/pic01/pic-03.jpg http://url/0530/pic01/pic-04.jpg  http://url/0530/pic02/pic-01.jpg http://url/0530/pic02/pic-02.jpg http://url/0530/pic02/pic-03.jpg http://url/0530/pic02/pic-04.jpg  http://url/0530/pic03/pic-01.jpg http://url/0530/pic03/pic-02.jpg http://url/0530/pic03/pic-03.jpg http://url/0530/pic03/pic-04.jpg 

i think can use applescript in automator before result sent text editor. have coding advice?

===================================================

thanks @ user309603 , @ mklement0 much!!

i choose pure applescript method. here code in automator run applescript in workflow:

on run {input, list}      set txtg first item of input      repeat txtline in items 2 thru -1 of input         if txtline contains "-01" set txtg txtg & linefeed         set txtg txtg & linefeed & txtline     end repeat      return txtg  end run 

here pure applescript solution. prefer mklement0's awk-solution. faster if have long url-lists.

set txt "http://url/0530/pic01/pic-01.jpg  http://url/0530/pic01/pic-02.jpg http://url/0530/pic01/pic-03.jpg http://url/0530/pic02/pic-01.jpg http://url/0530/pic03/pic-01.jpg http://url/0530/pic03/pic-02.jpg http://url/0530/pic03/pic-03.jpg http://url/0530/pic03/pic-04.jpg http://url/0530/pic04/pic-01.jpg"  set txtg first paragraph of txt  repeat txtline in paragraphs 2 thru -1 of txt     if txtline contains "-01" set txtg txtg & linefeed     set txtg txtg & linefeed & txtline end repeat  return txtg 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -