我对 AppleScript 几乎一无所知,可以提供一些帮助。
在运行时,我的广播播放系统 (MegaSeg) 将当前播放的曲目的详细信息写入一个名为“NowPlaying”的文本文件,该文件仅包含以下内容,每个内容都在自己的行中且不带方括号:
Title: [title]
Artist: [artist]
Album: [album]
Time: [time in some format or other]
我想将它传递给我的广播流媒体 LadioCast,它可以通过 AppleScript 进行寻址,以便它将有关正在播放的内容的信息发送到流媒体服务器。MegaSeg 不支持 Applescript 调用,例如“告诉应用程序“MegaSeg”...将 trackName 设置为当前曲目的名称”,所以我不能那样做。我不知道该怎么做。
如果我们想象我能够获取该信息,我会这样做:
set lastName to ""
set lastArtist to ""
set lastAlbum to ""
repeat
** insert missing file reading section here
** in the following, "title", "artist" and "album" are from the text file **
set trackName to title
set trackArtist to artist
set trackAlbum to album
** end of missing section
if trackName is not lastName and trackArtist is not lastArtist and trackAlbum is not lastAlbum then
set lastName to trackName
set lastArtist to trackArtist
set lastAlbum to trackAlbum
tell application "LadioCast"
set metadata song to trackName & " – " & trackArtist & " – " & trackAlbum
end tell
end if
delay 15
end repeat
提前致谢。——理查德·E
===
我尝试了@DigiMonk 的建议,它们非常有帮助,但并非所有这些都有效。首先,文件在特定位置,而不是在桌面上;其次,我根本无法让“trim_line”工作 - 我收到“脚本不理解 trim_line 消息”。但是文件中的文本似乎已经被修剪了。
下面的脚本几乎可以工作;从 Applescript 编辑器运行时,它似乎确实将 Title、Artist 和 Album 放入变量中。但是,当我尝试从 LadioCast 运行它时,我收到 EOF -39 错误。更重要的是,一旦我运行它,MegaSeg 就会永远停止更新文件。我大概锁定了文件以从中读取并停止 MegaSeg 写入它。我该如何避免这种情况?
set lastName to ""
set lastArtist to ""
set lastAlbum to ""
set lastTime to ""
set trackName to ""
set trackArtist to ""
set trackAlbum to ""
set sourcePath to ""
repeat
set sourcePath to open for access file "Library:MegaSeg User Data:Logs:Logs for MegaSeg System (4):NowPlaying"
set thisText to read sourcePath as text
close access file "Library:MegaSeg User Data:Logs:Logs for MegaSeg System (4):NowPlaying"
set the paragraphList to every paragraph of thisText
repeat with i from 1 to number of items in paragraphList
set thisItem to item i of paragraphList
if thisItem starts with "Title:" then
set x to the offset of "Title:" in thisItem
set trackName to (text (x + 6) thru -1 of thisItem)
else if thisItem starts with "Artist:" then
set x to the offset of "Artist:" in thisItem
set trackArtist to (text (x + 7) thru -1 of thisItem)
else if thisItem starts with "Album:" then
set x to the offset of "Album:" in thisItem
set trackAlbum to (text (x + 6) thru -1 of thisItem)
end if
end repeat
if trackName is not lastName and trackArtist is not lastArtist and trackAlbum is not lastAlbum then
set lastName to trackName
set lastArtist to trackArtist
set lastAlbum to trackAlbum
tell application "LadioCast"
set metadata song to trackName & " – " & trackArtist & " – " & trackAlbum
end tell
end if
delay 15
end repeat