我正在尝试使用带有以下代码的applescript来获取桌面窗口的边界:
tell application "Finder"
get bounds of window of desktop
end tell
Run Code Online (Sandbox Code Playgroud)
我一直得到"执行错误:Finder收到错误:无法获得桌面窗口的界限.( - 1728)".
我正在跑狮子.知道我怎么能让这个工作吗?
桌面和窗口是两个不同的东西.桌面实际上是一个位于的文件夹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
Run Code Online (Sandbox Code Playgroud)
请注意检查是否有任何窗口实际打开,因为如果没有打开窗口,Applescript将返回错误.
如果您想要获得屏幕的界限,那么您需要的只是以下内容......
tell application "Finder"
get bounds of window of desktop --> weird but that's Applescript for you
end tell
--> Result: {0, 0, 1440, 900}
Run Code Online (Sandbox Code Playgroud)
如果启用退出Finder或使其消失的功能,则上述操作无效.
| 归档时间: |
|
| 查看次数: |
1985 次 |
| 最近记录: |