2016-04-29 35 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等笨拙的標準化框架支配。

相關問題