【问题标题】:Applescript folder action to add new files to iTunes playlist将新文件添加到 iTunes 播放列表的 Applescript 文件夹操作
【发布时间】:2019-09-12 17:58:27
【问题描述】:

我正在尝试为保管箱文件夹创建一个 applescript,以便在将新文件添加到文件夹时,它会自动将该文件添加到 iTunes 中的特定播放列表中(目标是能够更新多台计算机'只需将一个文件添加到一个保管箱文件夹即可远程播放列表。)

除了将文件添加到 iTunes 播放列表外,AppleScript 也可以使用。调试有点棘手,因为它是一个文件夹操作,所以它不能在脚本编辑器中运行。我一直在使用显示对话框来尝试了解正在发生的事情,但对话框显示的信息对我来说看起来像是正确的信息,所以我很难过。非常感谢任何帮助!

我尝试使用 POSIX 路径,我尝试将项目设置为别名,作为字符串,我尝试使用 "\"" & item & "\"" 将项目设置为另一个变量

set playlistToUpdate to "Public News Service"

on adding folder items to theFolder after receiving theNewItems
    set filesAdded to {}
    repeat with i from 1 to count of theNewItems
        set thisItem to item i of theNewItems as alias
        tell application "iTunes"
            launch
            delay 2
            display dialog thisItem
            add thisItem to playlist playlistToUpdate
        end tell
    end repeat
end adding folder items to

【问题讨论】:

    标签: applescript dropbox itunes


    【解决方案1】:

    除非您执行诸如使用带有警报对话框的try 语句之类的操作,否则文件夹操作将静默失败。在您发布的示例中,将display dialog 与别名一起使用而不是首先将其强制为字符串会出错。

    我发现通过将功能分解为自己的处理程序并添加 runopen 处理程序,可以从 脚本编辑器 测试和运行脚本或作为applet/droplet,除了用作文件夹动作之外,例如:

    property playlistToUpdate : "Public News Service"
    
    on run -- applet or from the Script Editor
        doStuff for (choose file with multiple selections allowed)
    end run
    
    on open droppedItems -- droplet
        doStuff for droppedItems
    end open
    
    on adding folder items to theFolder after receiving theNewItems -- folder action
        doStuff for theNewItems
    end adding folder items to
    
    to doStuff for someItems -- the main stuff
        set filesAdded to {}
        repeat with anItem in someItems
            tell application "iTunes"
                launch
                delay 2
                display dialog (anItem as text)
                add anItem to playlist playlistToUpdate
            end tell
        end repeat
    end doStuff
    

    【讨论】:

    • 感谢您的回复!这绝对是我一直在尝试调试的一个步骤。不幸的是,我仍然无法弄清楚applescript有什么问题......
    • 它适用于我的常规文件夹,是在Folder Actions Setup... 中设置的文件夹和操作吗?
    • 在文件夹操作设置中设置。这很奇怪——对我来说,它会启动 iTunes,但不会将文件添加到播放列表中。它可能与Dropbox文件夹内的文件夹有关吗?疯狂的是,这有效:code 将 playlistToUpdate 设置为“公共新闻服务”,将 itemToAdd 设置为“Macintosh HD:Users:Shared:Dropbox (Wave Farm):WGXC Studio Audio:Public News Service:Mamas 96 K Master 3.24 RUNAWAY MOON .mp3”作为别名告诉应用程序“iTunes”启动添加 itemToAdd 到播放列表 playlistToUpdate 结束告诉code 但不是当它附加到文件夹时...
    • Dropbox 应该像文件夹一样工作 - 如果将其附加到常规文件夹,它是否工作?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-02
    • 1970-01-01
    • 2013-09-11
    • 2017-03-13
    • 2012-07-03
    相关资源
    最近更新 更多