osacompile 更改 AppleScript 输出,使其无法运行 [英] osacompile changing the AppleScript output so it won't run
问题描述
我有一个半长的 AppleScript,我每天早上运行它来启动我的所有应用程序等.它所做的一件事就是启动一些应用程序,然后立即将它们最小化.当我将 .applescript 源代码粘贴到脚本编辑器并运行它时,一切正常:
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
但是当我按如下方式编译 AppleScript 源代码时:
But when I compile the AppleScript source as follows:
osacompile -o ~/Library/Scripts/myscript.scpt myscript.applescript
... 编译器将 minimize
修改为:
... the compiler munges minimize
to be:
on minimize(w)
set |miniaturized| of w to true
end minimize
我收到此错误:
错误邮件出错:无法将窗口 ID 30936 的 |小型化| 设为类型引用."数字 -1700 从 |小型化|参考窗口 ID 30936
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
有人知道我在这里做错了什么吗?出于版本控制的目的,我需要通过 osacompile
运行脚本.
Anyone have any clue what I'm doing wrong here? For purposes of version control, I need to run the scripts through osacompile
.
更新: 澄清一下,似乎正在发生的事情是脚本编辑器在命令行上编译方法与 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)?
推荐答案
您的代码没有任何问题 - 我怀疑这是 osacompile
中的错误,我建议您向 Apple 提交了错误报告 - 正如我所做的那样.
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.
您可以通过使用 AppleScript Editor
将其直接保存为 *.scpt
文件然后使用 osascript
运行它来验证您的代码是否正常工作代码>.[更新] 相比之下,将 *.applescript
源代码文件直接传递给 osascript
确实会出现问题.
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.
我没有理由认为基于 AppleScript Editor
的编译与 osacompile
(以及 osascript
中的按需编译)的工作方式不同代码>),在这种情况下,前者的行为是预期和期望的行为.
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.
有 2 个解决方法:
在
使用应用程序系统事件"
块中的术语中包含对小型化
的引用:这是一种通用的解决方法,适用于任何 AppleScriptable 应用程序的窗口.
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
内联小型化命令而不是调用子程序:
set miniaturized of window 1 to true
这篇关于osacompile 更改 AppleScript 输出,使其无法运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!