Applescript:在由Applescript创建的Finder窗口中选择(高亮显示)文件

4

我最近从Windows 7切换过来。在苹果脚本方面,我是一个(非常)初学者。
为了通过热键创建新文件并显示对话框,我使用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 脚本 touch)。在需要时,我成功地将显示对话框放在前面,并在输入 thefilename 后,找到了窗口 this_folder

现在,我正在尝试选择/高亮新创建的文件(以便在长列表中轻松定位它)。我发现代码 open -R 可能是我要找的,然后尝试将其应用在底部:

open -R thefilename

并且

open -R this_folder/thefilename

我尝试重复使用之前输入的变量thefilename作为文件名,但不成功。
我不知道如何指定打开命令可能会显示的文件。

如果我的英语不完美,请谅解。

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

非常感谢!我只是在第二和第三段前面添加了“激活”! - chismah

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接