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

如何使用AppleScript将Calculator.app的计算结果复制到剪贴板

AppleScript 实现计算器结果复制到剪贴板方案

可用代码实现

方案1:直接读取计算器结果写入剪贴板(最稳定,不依赖选中状态)

无需依赖计算结果默认选中的状态,可直接读取计算器当前显示的数值(含小数)写入剪贴板,完整代码如下:

tell application "Calculator"
    set the clipboard to (value of static text 1 of window 1) as string
end tell

如果必须使用你给出的set the clipboard to {?????}的代码框架,可先读取结果存入变量后填入对应位置:

-- 提前读取计算器的当前计算结果
set calcResult to value of static text 1 of window 1 of application "Calculator"
-- 填入缺失部分即可
set the clipboard to calcResult as string

方案2:模拟CMD+C快捷键复制(依赖默认选中状态)

如果你想沿用「选中后按CMD+C复制」的逻辑,可通过系统事件模拟快捷键操作,无需手动拼接剪贴板内容:

activate application "Calculator"
tell application "System Events"
    keystroke "c" using {command down}
end tell

注意事项

  • 运行脚本前请确保Calculator.app处于正常打开状态,未被最小化
  • 如果粘贴目标支持数值类型,可将代码中的as string替换为as number,保留数值属性

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.27 00:57:03