file - 如何使用 AppleScript 在桌面上的文件夹中创建新文件?

标签 file applescript directory desktop

我正在尝试使用 AppleScript 在桌面上的文件夹中创建一个文件。

set blankPage to (((path to desktop) as string) & "text.txt")

我知道path to desktop指向桌面,但是如何让它指向桌面上的文件夹 ex. (“文本文件”)?

最佳答案

如果该文件夹存在,您可以使用 Finder 获取该文件夹的路径:

tell application "Finder"
    set blankPage to (folder "Text files" of (path to desktop) as text) & ¬
        "text.txt" as alias
end tell

要制作一个空文本文件,您可以像这样使用 Finder:
tell application "Finder"
    set blankPage to make new file at folder "Text files" of (path to desktop) ¬
        with properties {name:"text.txt"}
end tell

使用 shell 是一种更快的方法:
do shell script "> $HOME'/Desktop/Text files/text.txt'"

关于file - 如何使用 AppleScript 在桌面上的文件夹中创建新文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25760674/

相关文章:

java - 为什么这个单元测试说我的目录不存在,而它却存在?

尝试查找下一个最大值时出现 Python 算法错误

automation - 如何在预定时间运行applescript

javascript - 获取Mac中所有可见应用程序窗口进程的窗口标题和应用程序/进程名称

batch-file - 根据文件数量将文件从文件夹移动到新文件夹

python - 如何多次迭代一个文件?

android - 如何从绝对路径检索视频缩略图?

applescript - 如何获取应用程序包中的 Scripts 文件夹?

python - 如何为每个目录创建一个进程?

找不到 MySQL 文件或目录 ODBC