Why doesn't the first script work, but the second one does?

I want to replace line breaks in text, so I wrote the following code using Apple Script, why the first script doesn’t work, but the second one does. The difference between the two scripts is that the first one uses “{popclip text}”, while the second one uses the clipboard directly.

  1. Here’s the first script.
on replace_chars(this_text, search_string, replacement_string)
    set AppleScript's text item delimiters to the search_string
    set the item_list to every text item of this_text
    set AppleScript's text item delimiters to the replacement_string
    set this_text to the item_list as string
    set AppleScript's text item delimiters to ""
    return this_text
end replace_chars

set the popclip_text to "{popclip text}"
set the updated_text to my replace_chars(popclip_text, return, " ")

tell application "Bob"
	launch
	translate updated_text
end tell
  1. Here’s the second script.
tell application "System Events"
	keystroke "c" using {command down}
	delay 1
end tell

on replace_chars(this_text, search_string, replacement_string)
	set AppleScript's text item delimiters to the search_string
	set the item_list to every text item of this_text
	set AppleScript's text item delimiters to the replacement_string
	set this_text to the item_list as string
	set AppleScript's text item delimiters to ""
	return this_text
end replace_chars

set the clipboard_content to get the clipboard as text
set the updated_content to my replace_chars(clipboard_content, return, " ")
set the clipboard to updated_content

tell application "Bob"
	launch
	translate (the clipboard)
end tell

I’m curious when you say the second one doesn’t work what actually happens? error message? does it work in Script Editor?

The second script works.
The first script doesn’t work. It doesn’t give any hints, it doesn’t respond when you click on it. Because the first script takes a parameter like this: “{popclip text}”
But if I apply it like this, it will run.

tell application "Bob"
	launch
	translate  "{popclip text}"
end tell

Sorry, I misread which one works.

If you post the full extension including the config I will take a look.

Here is a link

Can you see my link? it’s a reply above

I have another question, why is it always “copy” on the top of the cursor, I tried to adjust the position of the other plugins, but the cursor always has the “copy” option?

That’s just how it is designed. When Copy is present, the bar always aligns Copy with the pointer.

I downloaded it. The one with “doesn’t work” seems to work for me. At least, it launched the Bob application.