【问题标题】:AppleScript Set Name of FileAppleScript 设置文件名
【发布时间】:2021-05-14 19:12:30
【问题描述】:

我对以下 AppleScript 代码有疑问:

repeat with index from 1 to jpgCount
    set currentFile to item index of jpgList
    if index is less than 10 then
        set numberPrefix to "000"
    else if index is less than 100 then
        set numberPrefix to "00"
    else if index is less than 1000 then
        set numberPrefix to "0"
    else
        set numberPrefix to ""
    end if
    set fileNumber to numberPrefix & index as string
    set the name of currentFile to "2021_0514" & "_" & fileNumber & ".JPG"
end repeat

我在突出显示行 set the name of currentFile to "2021_0514" & "_" & fileNumber & ".JPG" 时遇到错误,这很奇怪,因为它通常可以正常工作。

错误提示:

错误“Finder 出错:无法将别名“Macintosh HD:Users:UserName:Desktop:SourceFolder:TestFile001.jpg”设置为“2021_0514_0001.JPG”。”编号 -10006 来自别名“Macintosh HD:Users:UserName:Desktop:SourceFolder:TestFile001.jpg”

我该如何解决这个问题?

【问题讨论】:

  • 您没有提供足够的 code 让我们重现错误。请查看How to create a Minimal, Reproducible Example,然后添加相关的代码以便我们重现错误。
  • 错误 -10006 表示 errAEWriteDeniederrOSACantAssign 都可能意味着您没有写入权限。不过我可能是错的,我会更深入地研究这一点。

标签: applescript


【解决方案1】:

正如 cmets 中已经说明的那样,您的代码不足以重现错误,但我猜到您可以尝试什么。我在顶部添加了 3 行代码:

set this_folder to (choose folder with prompt "Pick the folder containing the images to process:") as string
tell application "System Events" to set jpgList to every file of folder this_folder
set jpgCount to count of jpgList

它对我来说非常有效。正如 cmets 中已经说明的那样,错误 -10006 意味着 errAEWriteDeniederrOSACantAssign 都可能意味着您没有写入权限。 问题可能涉及:

  1. 您不是机器的管理员
  2. 您正在尝试访问不属于活动用户的文件夹
  3. 在所有错误中,都表明您尝试访问路径“Macintosh HD:Users:UserName:Desktop:SourceFolder:”。如果您将此帖子的真实姓名更改为 UserName,那么这应该不是问题。

【讨论】:

    猜你喜欢
    • 2015-12-05
    • 2011-09-09
    • 1970-01-01
    • 2015-10-17
    • 1970-01-01
    • 1970-01-01
    • 2015-12-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多