【问题标题】:Applescript rename file in current folderApplescript重命名当前文件夹中的文件
【发布时间】:2014-11-23 14:12:41
【问题描述】:

我想更改文件夹中的文件名,该文件名并不总是相同,这取决于 applescript 的存储位置(与要更改的文件相同的文件夹)。

我用一个对话框制作了这个脚本来检查路径,它工作正常,但之后我得到一个错误(-1700,无法将“测试”更改为整数。为什么,以及如何解决这个问题?

tell application "Finder"    
    set thePath to POSIX path of ((path to me as string) & "::")    
    display dialog thePath buttons {"Clipboard", "OK"} default button 2    
    if the button returned of the result is "Clipboard" then
        set the clipboard to thePath
    end if
    set name of document file "test" of thePath to "test_OLD"
end tell

【问题讨论】:

    标签: applescript


    【解决方案1】:

    如果您使用的是 Finder,您只需要设置名称语句,则需要将路径从 posix 路径强制转换为 hfs 路径。

    您还可以删除整个 Finder 块并使用:

    tell application "System Events" to set name of file (thePath & "test") to "test2"
    

    【讨论】:

      【解决方案2】:

      这可能是一种更简单的语法方式吗?

       tell application "System Events"
              set name of file "/Users/Firebird/Documents/test2.jpg" to "/Users/Firebird/Documents/11.jpg"
          end tell
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-01-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多