Applescript重命名当前文件夹中的文件

时间:2014-11-23 14:12:42

标签: applescript

我想更改文件夹中的文件名并不总是相同,这取决于存储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

2 个答案:

答案 0 :(得分:1)

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

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

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

答案 1 :(得分:0)

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

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