如何通过 AppleScript 更改 iTunes 播放列表中歌曲的顺序
如何使用 AppleScript 命令将播放列表中的歌曲移动到列表中的不同位置?
我已经有了歌曲和播放列表,并且其中一个已经在另一个中了;我只需要改变立场。
我的目标是对用户选择的曲目进行排序;理想情况下,我希望将按顺序排列的轨道移动到第一个选择的轨道的位置,并在按顺序排列的轨道之后立即按顺序对所有其他选定的轨道进行排序。
How can I move a song that's in a playlist to a different position within the list with an AppleScript command?
I already have the song and the playlist, and the one is already in the other; I need only to change the position.
My goal is to sort the tracks that the user has selected; ideally, I'd want to move the first-by-order track to the position of the first-in-selection track, and order all the other selected tracks immediately and sequentially after the first-by-order one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
move
命令看起来确实有很多错误。在我的实验中,似乎无论您将曲目移动到哪个位置,它都会将其移动到播放列表的末尾。尽管效率有点低,但这应该仍然是可以管理的。其语法如下所示:您应该可以使用其他几种结构来代替“结束”,包括“播放列表“foo”的开始”、“播放列表“foo”的第 5 轨之后”之类的内容,以及“在播放列表“foo”的第 5 首曲目之前”,但这些似乎都没有按预期工作。但是,如果您基本上按照您想要的方式将曲目排序在列表中,您应该能够迭代该列表,告诉 iTunes 将每个曲目连续移动到播放列表的末尾,最后您会得到全部完成后排序。
The
move
command does appear to be pretty buggy. In my experimenting, it appears that no matter what location you give it to move a track to, it moves it to the end of the playlist. This should still be manageable though, if a bit inefficient. The syntax for this looks like:There are several other constructions you're supposed to be able to use instead of "end of", including things like 'beginning of playlist "foo"', 'after track 5 of playlist "foo"', and 'before track 5 of playlist "foo"', but none of those appear to work as expected. But, if you basically get your tracks in a list sorted the way you want, you should be able to just iterate the list, tell iTunes to move each track in succession to the end of the playlist, and you'd end up with the sorted order after it's all done.
这是一个解决方案,但它是间接的,因为它导入 XML 文件。
该脚本创建一个 XML 文件,例如从 iTunes 导出播放列表。
当脚本完成创建 XML 文件后,它会在 iTunes 中导入该文件,iTunes 创建另一个同名的智能播放列表,脚本切换到新的播放列表并删除原始播放列表。
它也适用于非连续选择。
此脚本在 (
Mac OS X 10.4 ... 10.7
) 和 (iTunes 7.5 ... 10.6.3
) 上运行。该脚本不适用于旧版本,我不知道新版本。
我知道:
Mountain Lion 使用
FreeBSD 的 grep
而不是GNU 的 grep
,FreeBSD 的 grep 在 Mountain Lion 上非常慢(根据数据,慢了 30 到 100 倍)我读过的内容),所以这个脚本也会很慢。Tunes 11 打破了在播放列表中
歌曲重复
的 AppleScript 命令。song Repeat
的值仍然可以用 get 读取,只是无法设置,所以在脚本中注释掉该行。Here is a solution, but it's indirect, because it imports an XML file.
The script creates an XML file, such as export a playlist from iTunes.
When the script has finished creating the XML file, it imports the file in iTunes, iTunes creates another Smart Playlist with the same name, the script switch to the new playlist and delete the original.
It work also on non-contiguous selection.
This script run on (
Mac OS X 10.4 ... 10.7
) , (iTunes 7.5 ... 10.6.3
).The script doesn't work on older versions, I don't know about newer versions.
I know :
Mountain Lion use
FreeBSD's grep
instead ofGNU's grep
, FreeBSD's grep is extremely slow on Mountain Lion (30 to 100 times slower according to what I read), so this script will also be slow.Tunes 11 breaks the AppleScript command to
song repeat
a playlist. The value ofsong repeat
can still be read with get, it just can’t be set, so comments the line in the script.这是一个使用
GUI 脚本
的脚本。但这种脚本很容易被破坏,具体取决于iTunes的版本或操作系统的版本。
用户必须调整
延迟
(取决于机器的速度)。用户还必须更改脚本中的本地化标题。
该脚本适用于
iTunes 10.6.3
和Mac OS X 10.5.8
,我不知道它是否适用于其他版本。您必须通过单击通用访问系统首选项窗格中标有“启用辅助设备访问”的复选框来启用
辅助功能框架
。您必须取消选中智能播放列表上的“实时更新”,否则脚本将无法工作,因为“剪切”菜单项被禁用。
完成后您可以重新检查。
Here is a script that uses the
GUI Scripting
.But this kind of script is easily broken depending on the version of iTunes or the version of the OS.
The user must adjust the
delay
(depending on the speed of the machine).The user must also change the localized title in the script.
This script works on
iTunes 10.6.3
andMac OS X 10.5.8
, I don't know if it works on other versions.You must enable the
Accessibility Frameworks
by clicking the checkbox labeled "Enable access for assistive devices" in the Universal Access System Preference pane.You must uncheck "Live updating" on the Smart Playlist, otherwise the script will not work because the "Cut" menu item is disabled.
You can recheck it after you have finished.
由于您对 Philip Regan 的帖子的评论,我查看了 iTunes 中的移动命令,它说它用于移动播放列表,所以它对您没有帮助。但是,您可以执行此操作,这基本上将在当前播放列表中按照您想要的方式重新创建播放列表顺序。
我在这里假设选择是连续的。如果不是,则必须调整此代码,但您可以使用这些想法来实现这一点。
注意:您必须输入一些代码来对选择进行排序,因为我无法真正从您的描述中得知您想要如何对选择进行排序。将该代码放在我标记为“在此进行排序”的区域中。其余代码应该按原样工作。
我希望这会有所帮助...祝你好运。
Because of your comment to Philip Regan's post, I looked at the move command in iTunes and it says it's for moving playlists, so it won't help you. However you can do this which will basically recreate the playlist order how you want in the current playlist.
I assume here that the selection is sequential. If it's not this code will have to be adjusted but you can use these ideas to accomplish that.
NOTE: you have to put in some code to do your sorting of the selection because I can't really tell how you want to sort the selection from your description. Put that code in the area I have marked "DO YOUR SORTING HERE". The rest of the code should work as-is.
I hope this helps... good luck.
您不能直接执行此操作,因为字典显示播放列表中曲目的
index
属性是仅获取的,而不是获取/设置的。我看到的解决这个问题的唯一方法是创建一个新的播放列表,按照您希望的顺序将曲目移动到新的播放列表中,然后丢弃旧的播放列表。
You can't do that directly because the Dictionary shows the
index
property of a track in a playlist is get-only, not get/set.The only way I see around this would be to create a new playlist, move the tracks into the new one in the order you want them to be in, then trash the old one.