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

如何在单行内处理AppleScript单句tell语句的返回值?

AppleScript单行获取Finder桌面窗口边界指定元素的解决方法

你尝试的写法无法生效,核心原因是AppleScript中针对应用(比如Finder)的tell命令块不能直接作为表达式嵌套在item of这类操作里。可以通过以下两种单行写法实现需求:

方法1:变量中转(单行形式)

set desktopBounds to tell application "Finder" to bounds of window of desktop; get item 3 of desktopBounds

方法2:用run script包裹应用脚本

get item 3 of (run script "tell application \"Finder\" to get bounds of window of desktop")

补充说明

AppleScript对应用的命令调用属于特定的“应用术语”执行逻辑,不能直接作为普通表达式的一部分参与运算。要么先把应用返回的结果存入变量,再对变量进行元素提取;要么通过run script将应用脚本作为字符串执行,拿到返回结果后再操作。

内容的提问来源于stack exchange,提问作者d-b

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 09:20:56