将AppleScript中的Skim注释类型作为字符串获取

时间:2014-09-10 19:56:32

标签: applescript

我在编写Mac PDF查看器应用程序Skim脚本时遇到了一些奇怪的问题。我正在尝试格式化Skim注释以便导出。我有一个处理程序,根据各种注释类型(文本注释,突出显示注释,锚定注释,下划线注释,通过注释)对事物进行不同的格式化。我不想在我的各种处理程序中调用Skim,所以我试图将注释类型作为字符串传递(而不是作为常量),但是当我从终端运行脚本时遇到一个奇怪的错误。这是一个简单的问题示例:

如果我使用以下代码保存脚本: tell application "Skim" to return type of (note 1 of front document) as string

我从AppleScript编辑器运行它,得到像"highlight note"这样的结果。但是,如果我从终端运行该脚本(例如osascript test.scpt),我会得到以下结果: «constant ****NHil»

因此,当我尝试运行if, then检查注释类型时,我的处理程序在从编辑器运行时工作,但从终端运行时失败(我想运行它们的唯一方法)。例如,此语句在编辑器中返回truereturn "highlight note" = («constant ****NHil» as string)但终端中的false

所以,我的问题:当从终端运行脚本时,如何将Apple脚本中的Skim注释类型作为字符串处理?

1 个答案:

答案 0 :(得分:0)

持续强制将失败,因为osascript没有加载术语只是为了运行已编译的脚本。

第一个解决方案:将AppleScript保存为" 文字"格式

osascript test.applescript

-

第二个解决方案(没有脚本文件):

osascript -e 'tell application "Skim" to (type of note 1 of front document) as text'

-

第三种解决方案(此AppleScript):

run script "tell application \"Skim\" to (type of note 1 of front document) as text"

-

第四种解决方案(此AppleScript):

tell application "Skim" to tell (get type of note 1 of front document)
    if it = text note then return "text note"
    if it = anchored note then return "anchored note"
    if it = circle note then return "circle note"
    if it = highlight note then return "highlight note"
    if it = underline note then return "underline note"
    if it = strike out note then return "strike out note"
    if it = line note then return "line note"
    if it = freehand note then return "freehand note"
end tell