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

如何修改Apple Script仅为Photos中无名称的照片设置名称?

修改AppleScript:仅为名称为空的照片设置新名称

以下是修改后的脚本,它只会对选中照片中名称为空的条目执行重命名操作:

tell application "Photos"
    activate
    set imageSel to (get selection)
    if (imageSel is {}) then
        error "Please select at least one image."
    else
        set adjustedCount to 0
        repeat with i from 1 to count of imageSel
            set next_image to item i of imageSel
            -- 检查当前照片名称是否为空
            if name of next_image is "" then
                set capture_date to (the date of next_image)
                set short_capture_date_string to the short date string of capture_date
                set capture_time_string to the time string of capture_date
                set new_title to short_capture_date_string & " _ " & capture_time_string & " _ rnd" & (random number 1000)
                tell next_image
                    set the name of next_image to the new_title as text
                    set the description of next_image to "" as text
                end tell
                set adjustedCount to adjustedCount + 1
            end if
        end repeat
    end if
    return ¬
        "Adjusted the names of " & adjustedCount ¬
        & ¬
        " photos."
end tell

关键修改说明

  • 新增adjustedCount变量,用于统计实际被修改的照片数量(而非选中总数)
  • 在循环内添加判断条件if name of next_image is "" then,仅当照片名称为空时才执行重命名和清空描述的逻辑
  • 返回的提示信息改为使用实际修改数量,结果更准确

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 11:49:59