Finder applescript:奇怪的行为

时间:2010-02-22 09:33:55

标签: macos scripting applescript finder

我在OSX Snow Leopard上(我在Leopard上遇到了同样的问题,但是..) 这是苹果脚本:

tell application "Finder" to set my_from to selection
tell application "Finder" to set my_to to target of window 2
tell application "System Events" to keystroke (ASCII character 31)
tell application "Finder" to move my_from to my_to

它将当前选择移动到第二个Finder窗口,但在实际移动之前,按向下箭头(我在列表视图中)前进到下一个文件,这样每次移动时我都不会丢失位置

问题是:它每隔一段时间都有效!你实际上必须执行两次才能使它工作!!

有人有想法吗?

2 个答案:

答案 0 :(得分:0)

尝试添加:

tell application "Finder" to activate

作为第一行。

答案 1 :(得分:0)

我唯一的测试是保存它作为一个应用程序并从Dock启动它,但仅仅通过合并Paul的激活建议(并将它们全部阻塞到一个告诉的乐趣),我无法让这个代码失败或需要两次点击:

tell application "Finder"
   activate
   set my_from to selection
   set my_to to target of window 2
   tell application "System Events" to keystroke (ASCII character 31)
   move my_from to my_to
end tell