get bounds of desktop with applescript

五迷三道 提交于 2019-12-07 09:41:20

问题


I'm trying to get the bounds of my desktop window by using applescript with the following code:

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

I keep getting "execution error: Finder got an error: Can’t get bounds of window of desktop. (-1728)".

I'm running Lion. Any idea how I can get this to work?


回答1:


The Desktop and a window are two different things. The Desktop is actually a folder located at Macintosh HD:Users:yourusername:Desktop:. If you mean that you want to get bounds of a window in the Finder, then you need to identify the window in question. Something like this will work...

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

Note the checking to see if any windows are actually open as Applescript will return an error if there are no windows open.

If you are looking to get the bounds of your screen, then all you need is the following...

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

If the ability to quit the Finder or make it disappear is enabled, then the above will not work.



来源:https://stackoverflow.com/questions/11488126/get-bounds-of-desktop-with-applescript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!