将删除的文件移动到文件夹X,否则只需使用Applescript打开X即可

将删除的文件移动到文件夹X,否则只需使用Applescript打开X即可,applescript,Applescript,我想创建一个Applescript,它模仿特定文件夹X的别名行为。如果文件被拖到其中,它们应该被移动到文件夹X,但如果只是双击Applescript,则应该打开文件夹X 我是一个Applescript新手,但根据我在web上找到的东西,我构建了工作部件:一个将拖动的文件移动到X,另一个打开X。我不知道如何将它们与“if…else”逻辑结合起来,因此如果没有拖动任何内容,则打开文件夹;但如果拖动对象,则会将其移动到X,但X不会打开 repeat with a from 1 to lengt

我想创建一个Applescript,它模仿特定文件夹X的别名行为。如果文件被拖到其中,它们应该被移动到文件夹X,但如果只是双击Applescript,则应该打开文件夹X

我是一个Applescript新手,但根据我在web上找到的东西,我构建了工作部件:一个将拖动的文件移动到X,另一个打开X。我不知道如何将它们与“if…else”逻辑结合起来,因此如果没有拖动任何内容,则打开文件夹;但如果拖动对象,则会将其移动到X,但X不会打开

    repeat with a from 1 to length of theDroppedItems
        set theCurrentDroppedItem to item a of theDroppedItems
        tell application "Finder"
            set folderMyFolder to folder "/Users/myname/myfolder"  
            move theCurrentDroppedItem to folderMyFolder
        end tell
    end repeat
end open

tell application "Finder" to open "Macintosh HD:Users:myname:myfolder"


当脚本包含
open
处理程序时,它将被传递到应用程序上,而
run
处理程序是双击应用程序时调用的处理程序。您不需要进行任何比较,只需将要执行的语句放在适当的处理程序中即可,例如:

property targetFolder : ((path to home folder) as text) & "path:to:myfolder"

on run
    tell application "Finder" to open folder targetFolder
end run

on open droppedItems
    repeat with anItem in droppedItems
        tell application "Finder" to move anItem to folder targetFolder
    end repeat
end open

请注意,查找程序不知道POSIX路径,因此要使用它们,您需要强制将路径指向查找程序可以处理的对象,或者使用确实知道POSIX路径的对象,例如系统事件。

您不能删除重复循环并简单地告诉app id“com.apple.Finder”吗要将droppedItems移动到targetFolder?@CJK是的,您可以,我只是想让大家明白,
droppedItems
是一个列表。好的,明白了。