【问题标题】:Applescript variable as folderApplescript 变量作为文件夹
【发布时间】:2017-04-27 12:21:39
【问题描述】:

我正在尝试编写一个 AppleScript,它接收一组文件(重要的是要注意,它们并不都在同一个文件夹中),将每个文件重命名为它所在文件夹的名称。到目前为止,我有什么在下面,但我收到一个错误,上面写着“无法获得 1 的容器”。数字 -1728 来自 的 1。

tell application "Finder"

set all_files to every item of (choose file with prompt "Choose the Files you'd like to rename:" with multiple selections allowed) as list

    repeat with a from 1 to length of all_files
        set folder_name to container of a
        set file_name to folder_name
    end repeat
end tell

【问题讨论】:

    标签: applescript


    【解决方案1】:

    出现错误是因为你尝试获取索引变量acontainer

    基本上缺少一行来获取对文件的引用,并且您想将文件的 name 设置为文件夹的 name

    tell application "Finder"
    
        set all_files to every item of (choose file with prompt "Choose the Files you'd like to rename:" with multiple selections allowed) as list
    
        repeat with a from 1 to length of all_files
            set a_file to item a of all_files
            set folder_name to name of container of a_file
            set name of a_file to folder_name
        end repeat
    end tell
    

    注意:请注意,代码会删除文件的所有扩展名。

    【讨论】:

      猜你喜欢
      • 2011-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-08
      • 2016-09-06
      • 1970-01-01
      相关资源
      最近更新 更多