2016-04-29 33 views
0

我想用AppleScript移动文件。这是我使用的代码:用AppleScript移动文件

on adding folder items to this_folder after receiving these_items 
    repeat with i from 1 to number of items in these_items 
     set this_item to item i of these_items 
     set the item_info to info for this_item 
     set the item_path to the quoted form of the POSIX path of this_item 

... 
... //irrelevant code here 
... 


     tell application "Finder" 
     move POSIX file item_path to POSIX file "/Users/mainuser/Desktop/Books" 
     end tell 

    end repeat 
end adding folder items to 

如果我用常规的路径,例如/Users/mainuser/Desktop/Test/test.png比它的伟大工程,更换item_path。我的问题可能是什么原因?

回答

1
these_items

alias说明符的数组,就不需要任何进一步的强迫

tell application "Finder" 
    move this_item to folder "Books" of desktop 
end tell 

的属性总是desktop点到当前用户的桌面。顺便说一句:Finder不接受POSIX路径(斜线分隔),只有本地HFS路径(冒号分隔)。

PS:item_path不起作用的原因是引用。
这只是需要do shell script

1

用途:

on adding folder items to this_folder after receiving these_items 
    tell application "Finder" to move these_items to folder "Books" of desktop 
end adding folder items to 

after receiving参数是AppleScript的别名值的列表,这是一件好事Finder的move命令已经理解并知道如何一起工作。虽然move等应用程序命令接受的值不是应用程序对象的引用,但它并不完全未知;特别是Finder等之前的OS X应用程序,其脚本支持完全是手写的,允许开发人员以对用户有用的方式工作,而不仅仅是由OS X的Cocoa Scripting等笨拙的标准化框架支配。

相关问题