使用 applescript 获取桌面边界 [英] get bounds of desktop with applescript

查看:26
本文介绍了使用 applescript 获取桌面边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用带有以下代码的 applescript 来获取桌面窗口的边界:

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

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

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

我正在运行 Lion.知道我怎样才能让它工作吗?

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

推荐答案

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

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

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

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}

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

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

这篇关于使用 applescript 获取桌面边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆