-1

I'm trying to modify the results of a list of 30 items from "Get Image URLs on Webpage".

For example:

"https://dspncdn.com/a1/media/236x/82/58/da/8258da274aa4b81ab00c9c92cf5bcf50.jpg",
  "https://dspncdn.com/a1/media/236x/4e/9a/75/4e9a75bec9041112751ca2dd08a45026.jpg",
  "https://dspncdn.com/a1/media/236x/33/83/46/338346575aa402b13cb778c9525018fb.jpg",

What I would like to do is replace "236x" with "originals".

The problem is that the closest I can get eliminates the " ", and line breaks, which renders makes Downloading impossible.

"https://dspncdn.com/a1/media/original/82/58/da/8258da274aa4b81ab00c9c92cf5bcf50.jpghttps://dspncdn.com/a1/media/original/4e/9a/75/4e9a75bec9041112751ca2dd08a45026.jpghttps://dspncdn.com/a1/media/original/33/83/46/338346575aa402b13cb778c9525018fb.jpghttps://dspncdn.com/a1/media/original/a1/4f/7b/a14f7b07c1fafb12fce1ccdd53b52e69.jpghttps://dspncdn.com/a1/media/original/30/42/64/304264157b118808f6702f82c043aa65.jpg

Etc.

Forgive me for being extremely noob. The code I'm using to make the change is:

on run {input}
    set input to replaceText("236x", "original", input as string)
end run

on replaceText(find, replace, textString)
    set prevTIDs to AppleScript's text item delimiters
    set AppleScript's text item delimiters to find
    set textString to text items of textString
    set AppleScript's text item delimiters to replace
    set textString to "" & textString
    set AppleScript's text item delimiters to prevTIDs
    return textString
end replaceText

I'm not sure of the right words to describe strings and paragraphs, truly noob, but I would guess that the preservation of each line in the paragraph might require something else entirely. Is it still a string if it has multiple lines?

Thanks in advance for any help can be given. I believe it's my final step to solving this.

2
  • Just repeat through the individual items instead of converting the input list to text.
    – red_menace
    Aug 11, 2022 at 16:30
  • I'm not sure what to modify to enable that.
    – Lex
    Aug 11, 2022 at 21:31

1 Answer 1

1

In a Run AppleScript action, the run handler's input parameter is a list of items from the previous action, and the result returned from the script is what gets passed on to any following action.

In your sample, You are mashing the input items together (by coercing to a string) and then later wanting to separate them. Since the input is already a list, you can just step through that list, building a new one (for output) from processing each item, for example:

on run {input, parameters}
   set output to {}
   repeat with anItem in input
      set end of output to replaceText("236x", "original", anItem as text)
   end repeat
   return output
end run

on replaceText(find, replace, textString)
   set prevTIDs to AppleScript's text item delimiters
   set AppleScript's text item delimiters to find
   set itemList to text items of textString -- split using old
   set AppleScript's text item delimiters to replace
   set textString to itemList as text -- join using new
   set AppleScript's text item delimiters to prevTIDs
   return textString
end replaceText

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .