2013-06-23 33 views
0

我想使用Apple脚本在桌面上选择一些文件(例如“test.txt”)。Apple脚本:选择桌面上的文件

我这样做:

tell application "System Events" to key code 103 

(模拟按键 “F11”),以显示桌面。

然后我想选择我的文件“test.txt”并在桌面上看到这个选择。此代码:

tell application "Finder" to select file "test.txt" of folder "Desktop" of home 

在“Finder”中选择我的文件。这不是我想要的。

我希望看到在桌面上的我的文件选择(而不是在Finder中的窗口,是显示文件夹“Dektop”)

+1

“这不是我想要的。”你想要做什么,或者为什么这不是你想要的? – Mark

+0

我想在桌面上看到我的文件的选择(不在Finder的窗口中,显示文件夹'Dektop') – user120084

+0

我已编辑我的文章 – user120084

回答

1

更改选择属性,而不是使用SELECT命令:

tell application "Finder" 
    set selection to item 1 of desktop 
end tell 

这也将保持现有选择:

tell application "Finder" 
    activate 
    select window of desktop 
    if selection is {} then set selection to item 1 of desktop 
end tell