【问题标题】:AppleScript path being replaced at compile time (New Keynote scripting trouble)AppleScript 路径在编译时被替换(新的 Keynote 脚本问题)
【发布时间】:2013-11-11 15:53:32
【问题描述】:

我们有一个applescript,它告诉主题演讲根据标准删除幻灯片。新的 keynote 没有 applescript 字典,但将旧的 keynote 保留在子目录中。所以我试图告诉 AppleScript 与旧应用程序而不是新应用程序对话。

如果我只是

tell application "Clean Install:Applications:iWork '09:Keynote.app"

它可以工作,但它不能识别任何主题词词典术语。 (删除幻灯片)。所以我需要把我的老朋友“使用条款”拉出来。这里的挑战是这是一个预编译指令,所以你必须使用字符串文字,由于不同的硬盘驱动器名称,我在最终用户的机器上没有。

好的,这里还有计划。我将使用“使用应用程序“Clean Install:Applications:iWork '09:Keynote.app”中的术语”写出一个新的 AppleScript 文件,然后执行该文件...天才...除了 AppleScript 编译时这一行:

using terms from application "Clean Install:Applications:iWork '09:Keynote.app"

更改为:

using terms from application "Keynote"

这当然会调用新的keynote的空字典。

关于如何防止 applescript 以这种方式帮助我的任何想法? (或者有更好的计划吗?)

完整代码:

using terms from application "Clean Install:Applications:iWork '09:Keynote.app"

    --using terms from application "Clean Install:Applications:iWork '09:Keynote.app"
    tell application "Clean Install:Applications:iWork '09:Keynote.app"

        activate

    end tell
end using terms from

非常感谢!

【问题讨论】:

    标签: scripting applescript keynote


    【解决方案1】:

    我在这里失明了(没有主题演讲)...但是您是否尝试过使用预定义的应用字符串作为变量和原始事件代码?

    您可以使用 Smile 轻松获取原始事件代码

    • 在 Smile 中创建一个新的脚本窗口;
    • 使用“操作”菜单中的“告诉”菜单项使该脚本窗口特定于应用程序(不告诉 需要阻止);
    • 写一行代码;选择代码行
    • 然后使用“复制翻译”菜单项 (cmd-shift-C) 复制原始事件代码
    • 将原始事件代码粘贴到具有您的工作(正常告诉块)脚本的不同窗口中

    这就是我为邮件应用程序执行此操作时的样子:

    set origMail to "MyDrive:Applications:Mail.app"
    
    tell application origMail
        delete («class mssg» 1 of «class mbxp» "INBOX" of «class mact» 1)
    end tell
    

    (当放入普通的tell块中时,该行代码将是“删除(帐户1的邮箱“INBOX”的消息1)”)

    【讨论】:

      【解决方案2】:

      我还没有尝试过,但我认为它会起作用...当您使用“使用术语”编译代码时,只需将新版本的 Keynote 放入垃圾箱即可。这应该迫使它使用旧版本的 Keynote 字典,并且您的代码应该可以编译。如果您随后将该代码保存为“applescript 应用程序”,那么它应该可以在任何人的计算机上运行,​​而无需重新编译。注意:您可能需要重新启动计算机才能使用此技巧。

      那么您就遇到了在用户计算机上定位正确应用程序的问题,因为他们也可能同时拥有这两个版本。这里有一些代码可以找到旧版 Keynote 的路径以及如何定位它。

      set lsregister to "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister"
      set appName to "Keynote.app"
      set nonapplescriptVersion to "6.0"
      
      -- get the path to all Keynote apps
      set appPaths to paragraphs of (do shell script lsregister & " -dump | grep " & quoted form of appName)
      
      -- find the one with a version number less than the nonapplescriptVersion of Keynote
      set appPath to missing value
      repeat with anApp in appPaths
          try
              -- extract the path
              set AppleScript's text item delimiters to "/"
              set tis to text items of anApp
              set thisPath to "/" & (items 2 thru end of tis) as text
              set AppleScript's text item delimiters to ""
      
              -- check the version
              if (version of application thisPath) is less than nonapplescriptVersion then
                  set appPath to thisPath
                  exit repeat
              end if
          end try
      end repeat
      if appPath is missing value then error "Needed application version not installed."
      
      -- use the older version
      using terms from application "Keynote"
          tell application appPath
              activate
              -- do whatever
          end tell
      end using terms from
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-11-24
        • 1970-01-01
        • 1970-01-01
        • 2010-12-12
        • 1970-01-01
        • 1970-01-01
        • 2013-12-07
        • 1970-01-01
        相关资源
        最近更新 更多