使用变量时无法对齐窗口→无法将{\“string \”}转换为整型
我是尝试使用来学习AppleScript。你在我的第一个雄心勃勃的项目的一部分下看到了什么。如果您还打开了“文本编辑”窗口,则会对其进行修改,以便在AppleScript编辑器中进行测试。使用变量时无法对齐窗口→无法将{“string ”}转换为整型
脚本的作用:
- 从列表中选择编辑
- 对准两个打开的窗口
我的问题:
对齐窗户只能如果我解雇变量。只要我将变量从返回的列表(selectedEditor
)与字符串tell process "TextEdit"
一起使用。
我希望有人可以发现错误。从事件
错误代码日志:
System Events got an error: Can’t make {"TextEdit"} into type integer.
下面的代码:
property myEditors : {"TextEdit", "Sublime Text 2"}
set the editorList to myEditors as list
set selectedEditor to choose from list the editorList
set lngWidth to word 3 of (do shell script "defaults read /Library/Preferences/com.apple.windowserver | grep -w Width")
set lngHeight to word 3 of (do shell script "defaults read /Library/Preferences/com.apple.windowserver | grep -w Height")
set lngHalf to lngWidth/2
set lngHeight to lngHeight - 22
tell application id "sevs"
tell process selectedEditor to tell window 1 to set {position, size} to {{lngHalf, 22}, {lngHalf, lngHeight}}
tell process "AppleScript Editor" to tell window 1 to set {position, size} to {{0, 22}, {lngHalf, lngHeight}}
end tell
错误“System Events出错:无法将{”TextEdit“}设置为整型。”告诉你这个问题。 {“TextEdit”}是包含一个项目的列表。这就是你从“从列表中选择”声明中得到的结果。因此,更改该声明到这...
set selectedEditor to item 1 of (choose from list the editorList)
这会给你“文字编辑”,这是一个字符串,而不是{“文字编辑”}这是一个列表。
此外,这种说法是不必要的,因为myEditors已经是一个列表,由括号括起。只需在“从列表中选择”命令中直接使用myEditor即可。
set the editorList to myEditors as list
我看到这个错误唯一的线索是,它是:
“errAEIllegalIndex:投放操作中指数超出范围”
我没有/自己标记,所以我不知道它与AppleScript的限制/潜力。由于您是AppleScript的新手,因此我会问您是否确定Marked.app不是可编写脚本的,也就是说,如果您确定它没有适当的脚本字典(完全没有)。将应用程序文件拖放到AppleScript Script编辑器会告诉你这个(要么显示你的应用程序的字典,要么告诉你它无法读取它)。使用系统事件的唯一原因是应用程序不可编写脚本,或者以非常有限的方式编写脚本。大多数具有有限脚本编写能力的应用程序都具有带属性的窗口对象。
例如,火狐(我现在使用它)具有有限的脚本化,并允许我设置了窗口的边界:
tell application "Firefox"
set bounds of window 1 to {137, 22, 1345, 809}
properties of window 1
end tell
...并同时获得它的windows'属性(tell中的第二行)。
对不起,如果这对你是显而易见的,并且你已经确定Marked没有这个功能,但是它是第一件要检查的东西,就像我说的,我没有标记。
这是问题的解决方案。谢谢@ regulus6633。 ///我的完整脚本仍然无法工作,但我设法找到了'其他错误',现在一切正常。 – pattulus