Osa*_*bie 6 pdf applescript text keynote
我编写了一个数据库 Web 应用程序来处理教堂礼拜歌曲,并且我正在尝试添加一个模块来输出选定的歌曲以投影歌词。我最初以为我所有的用户都在使用 Powerpoint,它可以导入一个简单的文本文件,每行前面有 0-5 个选项卡(0 个选项卡行成为新幻灯片的标题,一个或多个选项卡意味着一个“项目符号点”)级别对应于多少个选项卡)。因此,我的模块当前输出这样一个文本文件,演示者将打开一个按照他们想要的歌曲演示方式设计的 Powerpoint 模板,插入文本文件作为新幻灯片的“大纲”,然后瞧。下面是在 Powerpoint 中使用的文本文件结构的一个小示例(其中一张日语幻灯片,通过利用下一级大纲以较小字体进行罗马化):
\n\nAs the Deer\n As the deer panteth for the water\n So my soul longeth after Thee\n You alone are my heart\'s desire\n And I long to worship Thee\nAs the Deer\n You alone are my strength, my shield\n To You alone may my spirit yield\n You alone are my heart\'s desire\n And I long to worship Thee\n\xe9\xb9\xbf\xe3\x81\xae\xe3\x82\x88\xe3\x81\x86\xe3\x81\xab (As the Deer)\n \xe8\xb0\xb7\xe5\xb7\x9d\xe3\x81\xae\xe6\xb5\x81\xe3\x82\x8c\xe3\x82\x92\xe3\x80\x80\xe3\x81\x97\xe3\x81\x9f\xe3\x81\x86\xe9\xb9\xbf\xe3\x81\xae\xe3\x82\x88\xe3\x81\x86\xe3\x81\xab\n tanigawa no nagare o shitau shika no yoo ni\n \xe4\xb8\xbb\xe3\x82\x88\xe3\x80\x81\xe3\x82\x8f\xe3\x81\x8c\xe9\xad\x82\xe3\x80\x80\xe3\x81\x82\xe3\x81\xaa\xe3\x81\x9f\xe3\x82\x92\xe3\x81\x97\xe3\x81\x9f\xe3\x81\x86\n shu yo, waga tamashii anata o shitau\n\xe9\xb9\xbf\xe3\x81\xae\xe3\x82\x88\xe3\x81\x86\xe3\x81\xab (As the Deer)\n \xe3\x81\x82\xe3\x81\xaa\xe3\x81\x9f\xe3\x81\x93\xe3\x81\x9d\xe3\x80\x80\xe3\x82\x8f\xe3\x81\x8c\xe7\x9b\xbe\xe3\x80\x81\xe3\x80\x80\xe3\x81\x82\xe3\x81\xaa\xe3\x81\x9f\xe3\x81\x93\xe3\x81\x9d\xe3\x80\x80\xe3\x82\x8f\xe3\x81\x8c\xe5\x8a\x9b\n anata koso waga tate, anata koso waga chikara\n \xe3\x81\x82\xe3\x81\xaa\xe3\x81\x9f\xe3\x81\x93\xe3\x81\x9d\xe3\x80\x80\xe3\x82\x8f\xe3\x81\x8c\xe6\x9c\x9b\xe3\x81\xbf\xe3\x80\x80\xe3\x82\x8f\xe3\x82\x8c\xe3\x81\xaf\xe4\xb8\xbb\xe3\x82\x92\xe3\x81\x82\xe3\x81\x8a\xe3\x81\x90\n anata koso waga nozomi, ware wa shu o aogu\nRun Code Online (Sandbox Code Playgroud)\n\n但我教会的牧师(他的电脑是用来投影的)和除了我之外选歌的另外两位敬拜领袖都使用Mac。他们总是谈论 Powerpoint 幻灯片,所以我猜想这就是他们使用的幻灯片。但就在我完成输出选项卡式文本的代码时,我发现当他们说“Powerpoint”时,他们实际上指的是Keynote,它无法使用纯文本文件。旧版本的 Keynote 内部以 XML 形式存储幻灯片数据 ( https://www.xml.com/pub/a/2004/01/07/keynote.html ),但较新的 Keynote 版本逐渐使用更加不透明的格式 ( http:// justsolve.archiveteam.org/wiki/IWork)。Apple 显然不想要任何东西,除了 Keynote 创建或编辑 Keynote 演示文稿。
\n\n因此,我正在寻找有关如何解决此问题的建议。我想要一个不涉及我为他们创建 Powerpoint 文件以转换为 Keynote 的过程。不但每周都不能循环,而且转换的时候还存在一些行距问题。
\n\n我知道如何使用 LaTeX 从数据生成 PDF(我目前只对打印的弦表执行此操作,但我确信我可以弄清楚如何进行幻灯片式布局),但 Keynote 显然只导入一页一次 PDF - 典型的周日礼拜集大约有 30-50 张幻灯片,所以这会很烦人。另外,我希望敬拜领袖/牧师能够在必要时调整 Keynote 中的内容 - 如果它来自 PDF,那是不可能的。因此,我的第一个选择是以某种方式将 Keynote“模板”与某种类型的文本(XML、JSON、选项卡式文本或其他内容)结合起来。
\n\n这段对话似乎暗示使用 Applescript(听起来像是 Office 的 VBA 的 iWorks 等价物)可能是可行的,但由于我没有 Mac,这需要长时间借用别人的 Mac。计算机来学习语言并开发/测试脚本(除非它足够简单以至于你们中的一个人愿意为我制作一些东西)。有想法吗?
\n\n编辑:在 CJK 的回答和评论之后,我意识到最终结果的示例可能有助于形象化我正在尝试做的事情。这是来自 Powerpoint 的两张幻灯片,选择了日语幻灯片示例,因为如果我能让它发挥作用,英语幻灯片就很容易了。一周前,当我尝试将这个 Powerpoint 导入 Keynote 时,最顽固的样式是日语(一级“项目符号”)和罗马化(二级)的行距。
\n\n(如果您想知道,是的,那就是底部的标题框 - 我知道这很不传统,但由于天花板较低,我们幻灯片的上半部分是主要的不动产。)
\n\n\n\n在下一个示例(非季节性版本)中,我添加了 Powerpoint 的文本文件导入不支持的内容,因为 CJK 的方法启发我了解如何在脚本中使用富文本来完成此操作: 两个标题框中的不同文本格式。(之前我计划将版权信息放在每首歌的最后一张幻灯片上,位于使用 3 级或 4 级“项目符号”样式的歌词下方。但我更喜欢标题。)\n
编辑 2:尝试从 CJK 脚本跳板,这里尝试使用现有的母版幻灯片(如“标题和项目符号”)和段落样式(完全未经测试 - 只是在线示例中的一些内容)。我将在两天内对其进行测试,但我将其放在这里,以便 CJK 可以看到我到目前为止所做的事情:
\n\n-- *** I\'d like to use relative path so it would be portable, but (path to home folder as text) gave errors ***\nproperty SambiDBTextFile : "/Users/Rachel/Desktop/Songs.txt"\n\nproperty masterSlideName : "Lyrics" -- custom master slide based on "Title & Bullets"\n\n-- ** If I can use paragraph styles, I won\'t need these ***\nproperty TextSizes : {32, 28, 20}\nproperty TextColours : {"white", {63222,57568,41634}, {63222,57568,41634}}\nproperty TextFonts : {"Hiragino Kaku Gothic Pro", "Arial Italic", "Hiragino Kaku Gothic Pro"}\n\n-- ** This is what I really want to use, but I don\'t know if I can ***\nproperty TextStyles : {"Main Lyrics", "Romaji Lyrics", "Song Credits"}\n\nset AppleScript\'s text item delimiters to tab\nset notes to paragraphs of (read SambiDBTextFile)\n\ntell application "Keynote" to tell current document\n\n -- *** Check for master slide existence, and substitute if absent ***\n set masterSlideList to the name of every master slide\n if masterSlideName is not in masterSlideList then\n -- *** Create master slide? Nah, probably not possible ***\n display alert ("Master Slide") message "Master slide \'" & masterSlideName & "\' not found; using \'Title & Bullets\' instead."\n set masterSlideName to "Title & Bullets"\n end if\n\n -- Create slides with content from Keynote text file\n repeat with i from 1 to number of notes\n if item i of notes is "" then exit repeat -- EOF\n\n -- Get the text (without tabstops) and the level of indentation\n set [TextContent, TabValue] to [last text item, number of rest of reverse of text items] of item i of notes\n\n if TabValue is 0 then -- Indicates title of new slide\n set current slide to make new slide with properties {base slide:master slide masterSlideName}\n set object text of the default title item to TextContent\n else -- TabValue is not 0, indicating lyrics\n if TabValue > 3 then set TabValue to 3\n\n -- *** I have no idea if this will work, but the point is to append\n set object text of default body item to object text of default body item & TextContent & return\n\n -- *** Style the line just added ***\n -- *** Plan A: use paragraph styles (not sure if I can do this) ***\n set paragraph style of paragraph ((count of paragraphs of default body item) - 1) of default body item to item TabValue of TextStyles\n\n -- *** Plan B: hardcoded styling (uncomment if above line doesn\'t work) ***\n --tell paragraph ((count of paragraphs of default body item) - 1) of default body item\n --set its color to item TabValue of TextColours\n --set its font to item TabValue of TextFonts\n --set its size to item TabValue of TextSizes\n --end tell\n end if\n end repeat\nend tell\nRun Code Online (Sandbox Code Playgroud)\n
今天玩了一下Keynote和 AppleScript,我认为下面的脚本将产生符合您想要的内容。它包括根据正在解析的文本文件中每行的制表级别 (1-5) 设置不同文本设置的选项。
\n\n property KeynoteTextFile : "/Users/CK/Desktop/Keynote.txt"\n\n property PresentationTitle : "My Presentation"\n property _W : 1024 -- The width of each slide\n property _H : 768 -- The Height of each slide\n\n -- Text properties for the cover title and each slide title\n property CoverTextStyle : {font:"Arial Bold", color:"white", size:96}\n property TitleTextStyle : {font:"Arial Bold", color:"white", size:48}\n\n -- Spacing above and below the title of each slide\n property TitleMargins : {top:30, bottom:100}\n -- Spacing between lines in the body of each slide\n property VerticalSpacing : 75\n\n -- Text properties for the body of each slide for\n -- each level of tabulation\n property Tabulations : {0.1, 0.2, 0.3, 0.4, 0.5}\n property TextSizes : {32, 28, 24, 20, 16}\n property TextColours : {"white", "blue", "green", "magenta", "orange"}\n property TextFonts : {"Arial", "Arial Italic", "Times New Roman Bold", \xc2\xac\n "Times New Roman Bold Italic", "Times New Roman Italic"}\n\n\n set AppleScript\'s text item delimiters to tab\n set notes to paragraphs of (read KeynoteTextFile)\n\n -- Create new presentation with cover slide\n tell application "Keynote" to tell (make new document with properties \xc2\xac\n {document theme:theme "Black", width:_W, height:_H})\n\n set MyPresentation to it\n\n set base slide of current slide to master slide "Blank"\n\n tell the first slide to \xc2\xac\n set CoverTitle to make new text item \xc2\xac\n with properties {object text:PresentationTitle}\n\n set properties of object text of the CoverTitle to CoverTextStyle\n end tell\n\n -- Create slides with content from Keynote text file\n repeat with i from 1 to number of notes\n if item i of notes is "" then exit repeat -- EOF\n\n -- Get the text (without tabstops)\n -- and the level of indentation\n set [TextContent, TabValue] to \xc2\xac\n [last text item, number of rest of reverse of text items] \xc2\xac\n of item i of notes\n\n if TabValue is 0 then -- Indicates title of new slide\n tell application "Keynote"\n\n tell (make new slide at end of slides of MyPresentation) to \xc2\xac\n set Title to make new text item \xc2\xac\n with properties {object text:TextContent}\n\n set properties of object text of the Title to TitleTextStyle\n copy position of Title to [_x, _y]\n set position of Title to [_x, |top| of TitleMargins]\n\n end tell\n else -- TabValue is not 0, indicating slide content\n if TabValue > 5 then set TabValue to 5\n\n tell application "Keynote" to tell current slide of MyPresentation\n set n to number of text items\n\n set T to make new text item with properties \xc2\xac\n {object text:TextContent}\n\n tell object text of T\n set its color to item TabValue of TextColours\n set its font to item TabValue of TextFonts\n set its size to item TabValue of TextSizes\n end tell\n\n set position of T to \xc2\xac\n [(item TabValue of Tabulations) * _W, \xc2\xac\n VerticalSpacing * n + (|bottom| of TitleMargins)]\n\n end tell\n end if\n end repeat\n\n -- Go to first slide of presentation and bring Keynote\n -- into the foreground\n tell application "Keynote"\n set current slide of MyPresentation to first slide of MyPresentation\n activate\n end tell\nRun Code Online (Sandbox Code Playgroud)\n\n以下是我的Keynote.txt文件中的一些行:
\n\nThis is a Title\n This is indented by 1 tab\n So is this\n This is indented by 2 tabs\n This is 3 tabs\n Back to 1 tab\nRun Code Online (Sandbox Code Playgroud)\n\n产生了这张幻灯片:
\n\n\n\n请记住,实际幻灯片上的缩进级别不是由文本文件中的选项卡决定的,而是由tabulations脚本顶部定义的属性值决定的。因此,解析的文本文件中存在制表符的唯一效果是确定在幻灯片上呈现文本时应用于文本的一组特征(字体、颜色、大小和缩进独立于它的文本文件缩进)。
最后一点,我应该指出,文本文件中的行可以以 0-5 个制表符开始。6 个或更多选项卡将被视为只有 5 个选项卡。然而,重要的是,该行的其余部分不应在文本中包含任何制表符。按照脚本的情况,这会产生一些奇怪的结果。可以调整脚本以适应需要在文本中包含制表符的行,但我目前没有看到这种需要。
\n