用applescript限制桌面 [英] get bounds of desktop with applescript

查看:77
本文介绍了用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)".

我在跑狮子.知道如何使它起作用吗?

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}

如果启用了退出查找器或使其消失的功能,则以上操作将无效.

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

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

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