此代码获取两位的两位并将其复制到剪贴板。
一小段文字是html。在剥离所有html之前,我想用空行替换
标记。
我无法正确替换
,但是其余代码仍然有效。
任何想法我在做什么错。我还尝试使用return而不是换行符。
tell application "GarageSale 7"
repeat with theListing in (get selected ebay listings)
set des to get the description of theListing
set comment to get private comment of theListing
end repeat
end tell
set theText to des
to searchReplace(thisText, "<br>", linefeed)
set AppleScript's text item delimiters to searchTerm
set thisText to thisText's text items
set AppleScript's text item delimiters to replacement
set thisText to "" & thisText
set AppleScript's text item delimiters to {""}
return thisText
end searchReplace
on removeMarkupFromText(theText)
set tagDetected to false
set theCleanText to ""
repeat with a from 1 to length of theText
set theCurrentCharacter to character a of theText
if theCurrentCharacter is "<" then
set tagDetected to true
else if theCurrentCharacter is ">" then
set tagDetected to false
else if tagDetected is false then
set theCleanText to theCleanText & theCurrentCharacter as string
end if
end repeat
return theCleanText
end removeMarkupFromText
get the clipboard
set the clipboard to removeMarkupFromText(theText) & comment
答案 0 :(得分:0)
您已经定义了一个名为searchReplace()
的处理程序,但从未真正使用过它。这就是为什么您的脚本没有替换<br>
标签的原因。
首先,您要正确定义处理程序。它应采用以变量表示的参数。当前,您的最后两个参数是特定值:
to searchReplace(thisText, "<br>", linefeed)
这是建议的修改:
to searchReplace(thisText, searchTerm, replacement)
set my text item delimiters to searchTerm
set thisText to thisText's text items
set my text item delimiters to replacement
set thisText to thisText as text
set my text item delimiters to {""}
return thisText
end searchReplace
然后您可以像这样从脚本中调用它:
tell application "GarageSale 7"
repeat with theListing in (get selected ebay listings)
set des to get the description of theListing
set comment to get private comment of theListing
end repeat
end tell
set theText to searchReplace(des, "<br>", linefeed)
set the clipboard to removeMarkupFromText(theText) & comment