Applescript:在由applescript创建后,在finder窗口中选择(突出显示)一个文件

时间:2012-12-11 12:30:13

标签: file applescript

我最近从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脚本触摸)。
我成功地在需要时放置显示对话框,并在输入thefilename后,查找器窗口this_folder

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

open -R thefilename

open -R this_folder/thefilename

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

如果我的英语不完美,我道歉。

1 个答案:

答案 0 :(得分:1)

尝试:

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