我一生都无法弄清楚如何在 Keynote 6.2 中自动执行查找/替换功能。
我的目标是在整个文档中查找/替换。我有来自剪贴板的文本,我想用它替换字符串。
我最接近的是这个页面上的一个脚本,但它在 Keynote 6.2 中不起作用。
http://macscripter.net/viewtopic.php?id=26603
任何人都可以帮忙吗?
我一生都无法弄清楚如何在 Keynote 6.2 中自动执行查找/替换功能。
我的目标是在整个文档中查找/替换。我有来自剪贴板的文本,我想用它替换字符串。
我最接近的是这个页面上的一个脚本,但它在 Keynote 6.2 中不起作用。
http://macscripter.net/viewtopic.php?id=26603
任何人都可以帮忙吗?
只是根据调整您链接到的内容以使用我的 v6.2.2 的 Keynote 进行此操作。希望这可以帮助您入门(请注意 AppleScript 的 Keynote 词典中的示例):
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
之前和之后:
[编辑二]
以下代码要求用户搜索和替换字符串(使用两个对话框),并用替换的版本替换每个文本项的每次出现。default body item
奇怪的是,它包含default title item
但不改变文本(为此,您必须使用我第一次展示的示例的变体)。
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