osacompile改变AppleScript的输出,所以它不会运行 [英] osacompile changing the AppleScript output so it won't run
问题描述
我有一个半长的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 解决方法
括起来参考
小型化
在使用从应用程序系统事件条款
块:
这是一个通用的解决方法,应与窗户从任何AppleScriptable应用程序。上最小化(W)
利用应用程序系统事件条款#替代方法
集小型化的W至真
结束使用条款从
最终减少
内嵌小型化的命令来代替调用子程序的:
集小型化窗口1至真
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 withosascript
. [Updated] By contrast, passing the*.applescript
source-code file directly toosascript
does exhibit the problem.There is no good reason I can think of for
AppleScript Editor
-based compilation to work differently fromosacompile
(and on-demand compilation inosascript
), and the former's behavior is the expected and desired one in this case.There are 2 workarounds:
Enclose the reference to
miniaturized
in ausing 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屋!