Replace 在注释记号中查找/替换为Applescript

Replace 在注释记号中查找/替换为Applescript,replace,find,applescript,keynote,Replace,Find,Applescript,Keynote,在Keynote 6.2中,我始终无法理解如何自动执行查找/替换功能 我的目标是在整个文档中查找/替换。我有来自剪贴板的文本,我想用它替换字符串 我最近看到的是本页上的一个脚本,但它在Keynote6.2中不起作用 有人能帮忙吗?只是在调整链接以使用我的Keynote v6.2.2的基础上完成的。希望这能让您开始(请注意Keynote的AppleScript字典中的示例): 之前: 之后: [编辑] 要在注释记号项目中执行文本项(与“标题对象”或“正文对象”相反),可以执行以下操作(请注意,

在Keynote 6.2中,我始终无法理解如何自动执行查找/替换功能

我的目标是在整个文档中查找/替换。我有来自剪贴板的文本,我想用它替换字符串

我最近看到的是本页上的一个脚本,但它在Keynote6.2中不起作用


有人能帮忙吗?

只是在调整链接以使用我的Keynote v6.2.2的基础上完成的。希望这能让您开始(请注意Keynote的AppleScript字典中的示例):

之前: 之后:

[编辑] 要在注释记号项目中执行文本项(与“标题对象”或“正文对象”相反),可以执行以下操作(请注意,这是区分大小写的,当然,要执行多个项,将进行重复循环):

前后:

[编辑两个]

下面的代码要求用户搜索和替换字符串(使用两个对话框),并用替换的版本替换出现的每个文本项。奇怪的是,它包括
默认正文项
默认标题项
,但不改变文本(为了做到这一点,您必须使用我首先展示的示例的变体)

[编辑三个] 这将在幻灯片和文本项目之间循环(我真的希望这能让你达到你想要的目的):


我试过了,但似乎什么也没发生。我应该指出,我希望搜索/替换文档中文本的所有实例,而不仅仅是当前幻灯片。另外,我对标题本身并不感兴趣——文本的任何实例都应该更改。我能有效地瞄准它吗?你必须重复幻灯片的循环。但这对我有用。如果我们想弄清为什么它对你不起作用,你必须给出更多的线索/代码。我不使用文本标题和正文。我的布局中只有文本项,因此这些不是此搜索功能的目标。确定。我将更新答案,使其仅包含文本项。如果你能提供更多关于1)你的项目是如何组织的,2)你尝试过什么代码的信息,那将非常有帮助。我有一个excel电子表格,每行有6个条目。我必须将这些值插入我已在其中输入值占位符的注释记号模板(例如地址、名称等)。我想搜索/替换每行中数据的第1-6项,并将其替换为相应的注释记号演示文稿。某些数据在注释记号演示文稿中具有多个实例。到目前为止,我只是使用applescript激活excel,输入击键将选择器移动到下一个值,复制,返回到注释记号,搜索该列占位符标题,全部替换,返回excel并重复。
tell application "Keynote"
    tell document 1
        set slidebody to object text of default body item of current slide
        set slidebody to my searchnreplace("foo", "BEE", slidebody)
        set object text of default body item of slide 1 to slidebody
        set slidetitle to object text of default title item of current slide
        set slidetitle to my searchnreplace("foo", "AAK", slidetitle)
        set object text of default title item of slide 1 to slidetitle
    end tell
end tell

-- I am a very old search & replace function...
on searchnreplace(searchstr, replacestr, txt)
    considering case, diacriticals and punctuation
        if txt contains searchstr then
            set olddelims to AppleScript's text item delimiters
            set AppleScript's text item delimiters to {searchstr}
            set txtitems to text items of txt
            set AppleScript's text item delimiters to {replacestr}
            set txt to txtitems as Unicode text
            set AppleScript's text item delimiters to olddelims
        end if
    end considering
    return txt
end searchnreplace
tell application "Keynote"
    tell document 1
        set textObjectText to object text of text item 1 of current slide
        set adjustedText to my searchnreplace("Foo", "BEE", textObjectText)
        set object text of text item 1 of slide 1 to adjustedText
    end tell
end tell

-- I am the same very old search & replace function...
on searchnreplace(searchstr, replacestr, txt)
    considering case, diacriticals and punctuation
        if txt contains searchstr then
            set olddelims to AppleScript's text item delimiters
            set AppleScript's text item delimiters to {searchstr}
            set txtitems to text items of txt
            set AppleScript's text item delimiters to {replacestr}
            set txt to txtitems as Unicode text
            set AppleScript's text item delimiters to olddelims
        end if
    end considering
    return txt
end searchnreplace
tell application "Keynote"
    activate
    set q1 to display dialog "Enter Search String:" default answer "" buttons {"Cancel", "OK..."} default button 2
    set s to (text returned of q1)
    set q2 to display dialog "Enter Replace String:" default answer s buttons {"Cancel", "OK"} default button 2
    set r to (text returned of q2)


    tell document 1
        set ii to (count of text items of current slide)
        set textItemmax to ii
        repeat with i from 1 to textItemmax by 1
            set textObjectText to (object text of text item i of current slide) as text
            set adjustedText to my searchnreplace(s, r, textObjectText)
            set object text of text item i of current slide to adjustedText
        end repeat
    end tell
end tell

-- I am the same very old search & replace function...
on searchnreplace(searchstr, replacestr, txt)
    considering case, diacriticals and punctuation
        if txt contains searchstr then
            set olddelims to AppleScript's text item delimiters
            set AppleScript's text item delimiters to {searchstr}
            set txtitems to text items of txt
            set AppleScript's text item delimiters to {replacestr}
            set txt to txtitems as Unicode text
            set AppleScript's text item delimiters to olddelims
        end if
    end considering
    return txt
end searchnreplace
tell application "Keynote"
    activate
    set q1 to display dialog "Enter Search String:" default answer "" buttons {"Cancel", "OK..."} default button 2
    set s to (text returned of q1)
    set q2 to display dialog "Enter Replace String:" default answer s buttons {"Cancel", "OK"} default button 2
    set r to (text returned of q2)


    set slideMax to (count of slides of document 1)
    repeat with slideIndex from 1 to slideMax by 1
        set ii to (count of text items of slide slideIndex of document 1)
        set textItemmax to ii
        repeat with i from 1 to textItemmax by 1
            set textObjectText to (object text of text item i of slide slideIndex of document 1)
            set adjustedText to my searchnreplace(s, r, textObjectText as text)
            set object text of text item i of slide slideIndex of document 1 to (adjustedText as text)
        end repeat
    end repeat
end tell


-- I am the same very old search & replace function...
on searchnreplace(searchstr, replacestr, txt)
    considering case, diacriticals and punctuation
        if txt contains searchstr then
            set olddelims to AppleScript's text item delimiters
            set AppleScript's text item delimiters to {searchstr}
            set txtitems to text items of txt
            set AppleScript's text item delimiters to {replacestr}
            set txt to txtitems as Unicode text
            set AppleScript's text item delimiters to olddelims
        end if
    end considering
    return txt
end searchnreplace