Applescript 在iTunes中查找具有部分名称的歌曲

Applescript 在iTunes中查找具有部分名称的歌曲,applescript,itunes,Applescript,Itunes,我知道如何在播放列表中按名称播放一首歌曲,但假设我想这样做,以便在播放该歌曲时,空格和大小写不重要 因此,如果我想播放“someSong”、“someSong”或“someSong”,我仍然想播放播放列表中名为“someSong”的歌曲 我该怎么做 试试看: set yourSong to "yoursongname" set yourPlaylist to "your playlist" set searchString to {} repeat with i from 1 to count

我知道如何在播放列表中按名称播放一首歌曲,但假设我想这样做,以便在播放该歌曲时,空格和大小写不重要

因此,如果我想播放“someSong”、“someSong”或“someSong”,我仍然想播放播放列表中名为“someSong”的歌曲

我该怎么做

试试看:

set yourSong to "yoursongname"
set yourPlaylist to "your playlist"

set searchString to {}
repeat with i from 1 to count of yourSong
    set aChar to text i of yourSong
    if aChar ≠ space then
        set end of searchString to aChar & " *?"
    end if
end repeat
set searchString to searchString as text

tell application "iTunes" to set plTracks to name of every track of playlist yourPlaylist
set AppleScript's text item delimiters to linefeed
set plTracks to plTracks as text
set AppleScript's text item delimiters to {""}
set targetSong to do shell script "echo " & quoted form of plTracks & " | grep -Ei " & quoted form of searchString

log targetSong
display dialog "Now Playing: " & targetSong buttons {"Cancel", "OK"} default button "OK" giving up after 2

tell application "iTunes" to play track targetSong of playlist yourPlaylist

嘿-要检查这是否有效,我怎么打印?我尝试了log(var),但似乎没有任何作用。您可以在AppleScript编辑器中运行它来测试它。使用歌曲名称填充yourSong变量,歌曲名称不带空格且大小写错误。用歌曲所在的播放列表的名称填充yourPlaylist变量。我编辑了脚本以记录targetSong的值,并在播放前简要显示它。