4

我试图通过使用带有以下代码的applescript来获取我的桌面窗口的边界:

tell application "Finder"
    get bounds of window of desktop
end tell

我不断收到“执行错误:Finder 出错:无法获取桌面窗口的边界。(-1728)”。

我正在运行狮子。知道我怎样才能让它工作吗?

4

1 回答 1

6

桌面和窗口是两个不同的东西。桌面实际上是一个位于Macintosh HD:Users:yourusername:Desktop:. 如果您的意思是要在 Finder 中获取窗口的边界,那么您需要识别有问题的窗口。像这样的东西会起作用......

tell application "Finder"
    set windowCount to (count windows)
    if windowCount > 0 then
        set windowBounds to bounds of window 1 --> Note the '1'
        return windowBounds
    end if
end tell

请注意检查是否确实打开了任何窗口,因为如果没有打开任何窗口,Applescript 将返回错误。

如果您正在寻找屏幕的边界,那么您只需要以下内容......

tell application "Finder"
    get bounds of window of desktop --> weird but that's Applescript for you
end tell
--> Result: {0, 0, 1440, 900}

如果启用了退出 Finder 或使其消失的功能,则上述操作将不起作用。

于 2012-07-14T23:41:57.760 回答