Scripting 编译时替换AppleScript路径(新的注释记号脚本问题)

Scripting 编译时替换AppleScript路径(新的注释记号脚本问题),scripting,applescript,keynote,Scripting,Applescript,Keynote,我们有一个applescript,告诉keynotes根据条件删除幻灯片。新注释记号没有applescript字典,但将旧注释记号保留在子目录中。所以我试着告诉AppleScript使用旧的应用程序而不是新的应用程序 如果我只是 tell application "Clean Install:Applications:iWork '09:Keynote.app" 它可以工作,但不识别任何注释记号词典术语。(删除幻灯片)。因此,我需要拿出我的老朋友“使用术语”。这里的挑战是,这是一个预编译指令,

我们有一个applescript,告诉keynotes根据条件删除幻灯片。新注释记号没有applescript字典,但将旧注释记号保留在子目录中。所以我试着告诉AppleScript使用旧的应用程序而不是新的应用程序

如果我只是

tell application "Clean Install:Applications:iWork '09:Keynote.app"
它可以工作,但不识别任何注释记号词典术语。(删除幻灯片)。因此,我需要拿出我的老朋友“使用术语”。这里的挑战是,这是一个预编译指令,因此您必须使用字符串文字,由于不同的硬盘驱动器名称,最终用户的机器上没有字符串文字

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

using terms from application "Clean Install:Applications:iWork '09:Keynote.app"
将更改为:

using terms from application "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
非常感谢

我在这里瞎飞(没有基调)。。。但您是否尝试过使用预定义的应用程序字符串作为变量和原始事件代码

您可以使用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

(当放入一个普通的通知块时,该行代码将是“删除(邮箱“收件箱”中的邮件1,帐户1)”)

我没有尝试过,但我认为它会起作用。。。使用“using terms from”编译代码时,只需将新版本的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