我有这个AppleScript代码:
tell application "TextEdit"
set test to the bounds of window 1
end tell
display dialog test
但是我收到以下错误:
error "Can’t make {10, 22, 400, 1003} into type string." number -1700
from {10, 22, 400, 1003} to string
我需要使用哪种数据类型?
顺便说一句,我不希望它像你将它设置为某些数据类型时那样显示10224001003
。
答案 0 :(得分:2)
显示对话框语句只能显示字符串。窗口边界将作为数字列表返回给您。因此,您必须使用该信息创建一个字符串,以便显示它。有几种方法可以做到这一点,但这里有一个简单的方法,我们只是创建一个新的字符串,并将边界数字插入到我们想要的字符串中。你可以看到我让新字符串看起来像数字列表......但它确实是一个字符串。
tell application "TextEdit"
set boundsList to the bounds of window 1
end tell
set boundsString to "{" & ((item 1 of boundsList) as text) & ", " & ((item 2 of boundsList) as text) & ", " & ((item 3 of boundsList) as text) & ", " & ((item 4 of boundsList) as text) & "}"
display dialog boundsString