如何使用AppleScript在桌面上的文件夹中创建新文件?
问题描述:
我正在尝试使用AppleScript在桌面上的文件夹中创建文件。如何使用AppleScript在桌面上的文件夹中创建新文件?
set blankPage to (((path to desktop) as string) & "text.txt")
我知道path to desktop
点到桌面上,但我怎么得到它的进入点在桌面上的前一个文件夹。 (“文本文件”)?
答
如果该文件夹存在,你得到它的路径与搜索工具:
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
使用壳更快的方式:
do shell script "> $HOME'/Desktop/Text files/text.txt'"