4

我最近从 Windows 7 切换。我是 applescript 的(非常)新手。
要通过热键和显示对话框创建新文件,我使用 spark 和我部分找到的以下脚本:

try
    tell application "Finder" to set the this_folder ¬
        to (folder of the front window) as alias
on error -- Merci d ouvrir un dossier avec votre finder
    set the this_folder to path to desktop folder as alias
end try

activate
set thefilename to text returned of (display dialog ¬
"Create file named:" default answer "filename.txt")
set thefullpath to POSIX path of this_folder & thefilename
do shell script "touch \"" & thefullpath & "\""

activate application "Finder"

我了解它的作用(除了 shell script touch)。
我成功地在需要时将显示对话框放在前面,然后进入thefilenamefinder 窗口this_folder

我现在正在尝试选择/突出显示新创建的文件(以便在长列表中轻松找到它)。我找到了open -R可能是我正在寻找的代码,并尝试在底部应用它:

open -R thefilename

open -R this_folder/thefilename

我尝试重用thefilename之前输入的名称变量,但未成功。
我不知道如何指定 open 命令可能显示的文件。

如果我的英语不完美,我深表歉意。

4

1 回答 1

2

尝试:

try
    tell application "Finder" to set the this_folder ¬
        to (folder of the front window) as alias
on error -- Merci d ouvrir un dossier avec votre finder
    set the this_folder to path to desktop folder as alias
end try


set thefilename to text returned of (display dialog ¬
    "Create file named:" default answer "filename.txt")

tell application "Finder"
    set thefullpath to make new file at folder this_folder with properties {name:thefilename}
    select thefullpath
end tell
于 2012-12-11T12:44:54.450 回答