You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用AppleScript获取桌面边界时出现错误-1728的技术求助

搞定AppleScript获取桌面边界报错的问题

嘿,我来帮你解决这个Finder脚本报错的问题!你遇到的error "Finder got an error: Can’t get bounds of window of desktop." number -1728错误,其实是因为当Finder的桌面图标被隐藏时,window of desktop这个对象压根就不存在,脚本自然拿不到它的边界啦。

下面给你两个靠谱的解决办法:

方法1:恢复桌面图标显示(对应你提到的偏好设置方案)

先通过终端命令开启Finder的桌面图标显示,让桌面窗口对象恢复存在:

  • 打开「终端」应用
  • 输入以下命令并回车:
    defaults write com.apple.finder CreateDesktop -bool true
    
  • 重启Finder让设置生效,输入:
    killall Finder
    

这时候再运行你的原脚本:

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

就能正常返回桌面窗口的边界了!

方法2:直接获取屏幕边界(更稳定,不依赖桌面图标状态)

如果你只是想拿到整个屏幕的边界,其实不用依赖Finder,用System Events的方法更靠谱,不管桌面图标藏不藏都能生效:

tell application "System Events"
    get bounds of first screen
end tell

这个脚本会返回主屏幕的坐标(比如{0, 0, 1920, 1080}),和桌面窗口的边界完全一致哦。

内容的提问来源于stack exchange,提问作者yehoshuk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 10:03:21