Applescript和GarageSale查找并替换所选商品

时间:2019-08-30 02:51:30

标签: applescript

我在GS中找到了用于搜索和查找的脚本。它是从2008年开始的,因此它可能会对较早的版本6(而不是当前的版本7)造成损害。它的目的是在任何当前所选模板的描述中找到文本,并将其更改为用户键入的任何内容。它会正确显示搜索和替换框,并且运行无任何错误;但是,没有任何文字更改。

我已经尝试过发布者的论坛和文档; macscripter;和苹果的论坛。我曾尝试对其进行多次修改,但是这些更改会产生错误,导致其无法运行或无法运行,但无济于事。

我正在OS 10.13.6上使用GS 7.0.16。

代码似乎起源于此

https://macscripter.net/viewtopic.php?id=26963

关于如何修改它的任何想法?

set theReply1 to (display dialog "Enter text to replace" default answer "text" buttons {"Cancel", "Continue"} default button "Continue")
set origtext to text returned of theReply1

set theReply2 to (display dialog "Enter new replacement text" default answer "text" buttons {"Cancel", "Continue"} default button "Continue")
set replacetext to text returned of theReply2

to searchReplace(thisText, searchTerm, replacement)
  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

tell application "GarageSale"
  repeat with aTemplate in every selected template
    set origline to get the description of aTemplate
    set the description of aTemplate to my searchReplace(origline, origtext, replacetext)
  end repeat
end tell

更新:

我在此处下载了版本8的最新测试版:

enter link description here

上面的代码是为6编写的。发布者显然已将脚本语言从6更改为7。发布者在其网站上包含了当前版本7和beta 8的文档。这些内容更加匹配,因此我决定将我的数据导入8并与此一起使用Applescript。

我通过删除beta 8文档中的一些示例将上述代码修改为以下代码。该脚本将查找替换一行连续的文本。您必须从“预览”模式切换到“编辑”模式,然后复制要替换的html。通过从预览模式复制样式化的文本将无法正常工作。

发布者最终向beta 8添加了一个批量查找​​和替换功能,但它目前在查找其中包含html的字符串时遇到了问题。

您可以使用最新Beta 8的内置搜索来查找“这是一些文本”。但找不到“这是一些文字”
“更多文字”。上面的脚本将查找该文本。

以下脚本在GS 7.0.16中也可以使用。只需加载到Apple的脚本编辑器中,然后作为桌面上的应用程序进行编译即可。在GS中选择一个列表,或者在一个或多个充满列表的文件夹中选择一个,然后运行编译的脚本。如果将一个大字符串替换为另一个大字符串,发现将它们放入两个新的TextEdit文档中会很有帮助,这样我就可以轻松地将它们复制并粘贴到脚本显示的两个对话框中。

set theReply1 to (display dialog "Enter text to replace" default answer "text" buttons {"Cancel", "Continue"} default button "Continue")
set origtext to (text returned of theReply1)

set theReply2 to (display dialog "Enter new replacement text" default answer "text" buttons {"Cancel", "Continue"} default button "Continue")
set replaceText to text returned of theReply2

to searchReplace(thisText, searchTerm, replacement)
    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

tell application "GarageSale"
    repeat with theListing in (get selected ebay listings)
        set origline to get the description of theListing
        set the description of theListing to my searchReplace(origline, origtext, replaceText)
    end repeat
end tell

0 个答案:

没有答案