首页 > 解决方案 > Applescript 重命名应用程序文件夹中的文件

问题描述

我正在尝试使用脚本重命名应用程序文件夹中的文本文件。我正在尝试以下

tell application "Finder"

    set name of file "File.txt" of applications folder to "File.txt.OFF"

end tell

但这给出了一个错误:

Can’t get file "Text.txt" of applications folder.

它肯定在那里并称之为(它是复制和粘贴)。然后我尝试删除文件夹位:

set name of file "File.txt" of applications to "File.txt.OFF"

但是又出现了一个错误:

Finder got an error: Can’t set every application to "Text.txt.OFF".

任何帮助将非常感激。

干杯

标签: macosapplescript

解决方案


applications folder在 Finder 术语中并不指向标准文件夹/Applications。它似乎是对某些前 OS X 项目的遗留参考。

试试这个,但您可能没有更改名称的权限,并且无论如何都不鼓励您将任意数据(如文本文件)放入/Applications

set applicationsFolder to path to applications folder
tell application "Finder"
    set name of file "File.txt" of applicationsFolder to "File.txt.OFF"
end tell

或使用System Events

tell application "System Events"
    set name of file "File.txt" of applications folder of local domain to "File.txt.OFF"
end tell

推荐阅读