简体   繁体   English

AppleScript文件夹操作-仅将“下载”文件夹中的MP3自动添加到iTunes

[英]AppleScript Folder Action - Add Only MP3's from Download folder Automatically to iTunes

I am trying create an applescript that will automatically add only downloaded MP3's from my download folder as a Folder Action. 我正在尝试创建一个applescript,它将只自动将我的下载文件夹中下载的MP3添加为Folder Action。 I found the following script online and it works great except for two things: iTunes launches anytime I download anything from the Internet and also adds pretty much any file that iTunes is willing to add from that download folder. 我在网上找到了以下脚本,除了以下两点外,它可以很好地工作:iTunes可以在我从Internet下载任何内容时启动,并且还可以添加iTunes愿意从该下载文件夹中添加的几乎所有文件。 I've tried modifying the code about 15 different times and every time either iTunes does not launch, or iTunes launches for any file downloaded and does not add the file 我已经尝试在大约15个不同的时间修改代码,并且每次iTunes不启动,或者iTunes为下载的任何文件启动并且不添加文件时

The original code is: 原始代码是:

on adding folder items to my_folder after receiving the_files
    repeat with i from 1 to number of items in the_files
        tell application "iTunes"
            launch
            try
                set this_file to (item i of the_files)

                add this_file

            end try
        end tell
    end repeat
end adding folder items to 

Thanks for the help! 谢谢您的帮助!

To do this, you need to use if/then logic to filter for the files you want. 为此,您需要使用if / then逻辑来过滤所需的文件。 Something along the lines of this (which I did not test, so the syntax may be slightly off)... 与此类似的东西(我没有测试,所以语法可能略有偏离)...

on adding folder items to my_folder after receiving the_files
    repeat with i from 1 to number of items in the_files
        set theCurrentFile to item i of the_files
        if (name extension of (info for theCurrentFile)) = "mp3" then
            tell application "iTunes"
                launch
                try
                    set this_file to (item i of the_files)

                    add this_file

                end try
            end tell
        end if
    end repeat
end adding folder items to 

Or, why not use Automator to do this? 或者,为什么不使用Automator来做到这一点呢? It has an action for filtering files and an action for importing files into iTunes. 它具有用于过滤文件的操作和用于将文件导入iTunes的操作。 And, you can create a Folder Action with it. 并且,您可以使用它创建一个文件夹动作。 See my attached screenshot. 见我所附的截图。

在此处输入图片说明

Hope this helps. 希望这可以帮助。

-Ben -本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM