osacompile改变AppleScript的输出,所以它不会运行 [英] osacompile changing the AppleScript output so it won't run

查看:512
本文介绍了osacompile改变AppleScript的输出,所以它不会运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个半长的AppleScript,我每天早晨跑发动我所有的应用程序等。其中一个是它的事情之一是推出了几个应用程序,然后立即减少他们。当我粘贴.applescript源到脚本编辑器,并运行它,一切正常:

   - 剪断:
告诉应用程序邮件
    发射
    最大限度地减少我的(窗口1)
    检查新邮件
告诉结束
- '减少'定义为:
在减少(W)
    设置小型的W至真
最终减少

但是,当我编译的AppleScript来源如下:

  osacompile -o〜/资源库/脚本/ myscript.scpt myscript.applescript

...编译munges 减少是:

 上最小化(W)
    设置|微型| W的真
最终减少

和我得到这个错误:


  

错误的邮件得到了一个错误:不能让|微型|窗口ID 30936进入型号。微型|从数-1700 |窗口ID的30936引用<​​/ P>

任何人有任何线索,我在做什么错在这里?版本控制的目的,我需要osacompile 贯穿脚本。

更新::要澄清一下,似乎是发生的是,脚本编辑器编写不同的方法比 osacompile 在命令行上。难道是知道他们是否编译不同(的例如的应用范围,推论或者一些这样的东西)?


解决方案

有什么不对您的code - 我怀疑这是一个错误 osacompile 我建议您向苹果一个 bug报告 - 像我那样

您可以验证您的code。通过使用正常工作的AppleScript编辑器将其保存为 *。SCPT 文件直接,然后用 osascript 。
[更新]相比之下,传递。*的AppleScript 源 - code文件直接到 osascript 并表现出问题。

有没有好的理由,我能想到的的AppleScript编辑器编译基于从的工作方式不同osacompile (和按需在汇编 osascript ),以及前的行为的预期并在这种情况下,所希望的一个。

有2 解决方法

I have a semi-long AppleScript that I run each morning to launch all of my apps etc. One of the things that it does is launch a few apps and then immediately minimize them. When I paste the .applescript source into Script Editor and run it, everything works fine:

-- snip:
tell application "Mail"
    launch
    minimize(window 1) of me
    check for new mail
end tell
-- 'minimize' defined as:
on minimize(w)
    set the miniaturized of w to true
end minimize

But when I compile the AppleScript source as follows:

osacompile -o ~/Library/Scripts/myscript.scpt myscript.applescript

... the compiler munges minimize to be:

on minimize(w)
    set |miniaturized| of w to true
end minimize

And I get this error:

error "Mail got an error: Can’t make |miniaturized| of window id 30936 into type reference." number -1700 from |miniaturized| of window id 30936 to reference

Anyone have any clue what I'm doing wrong here? For purposes of version control, I need to run the scripts through osacompile.

UPDATE: To clarify, what seems to be happening is that Script Editor is compiling the method differently than osacompile on the command line. Is it known whether they compile different (e.g., using scope inferences or some such thing)?

解决方案

There is nothing wrong with your code - I suspect this is a bug in osacompile and I suggest you file a bug report with Apple - as I've done.

You can verify that your code works correctly by using AppleScript Editor to save it as a *.scpt file directly and then running it with osascript. [Updated] By contrast, passing the *.applescript source-code file directly to osascript does exhibit the problem.

There is no good reason I can think of for AppleScript Editor-based compilation to work differently from osacompile (and on-demand compilation in osascript), and the former's behavior is the expected and desired one in this case.

There are 2 workarounds:

  • Enclose the reference to miniaturized in a using terms from application "System Events" block: This is a generic workaround that should work with windows from any AppleScriptable application.

    on minimize(w)
        using terms from application "System Events" # WORKAROUND
             set miniaturized of w to true
        end using terms from
    end minimize
    

  • Inline the miniaturization command instead of calling a subroutine:

    set miniaturized of window 1 to true
    

这篇关于osacompile改变AppleScript的输出,所以它不会运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆