我通过AppleScript控制iTunes,我正在播放来自HTTP服务器的流。我正在使用的代码如下所示:
tell application "iTunes"
open location "your_url_here"
play
end tell
它工作正常,但我希望避免这些URL显示在iTunes资料库或之后的任何播放列表中。有没有办法实现这一目标?
答案 0 :(得分:1)
您是否考虑过使用QuickTimePlayer来播放流?
tell application "QuickTime Player"
open URL "http://www.a-1radio.com/listen.pls"
end tell
它应该打开所有iTunes格式,它作为OsX的默认设置,它更“最小”,不会保存曲目。
(我知道您指定要使用iTunes,因此这可能不是解决方案,但预装软件值得一试)
编辑要隐藏它,这似乎有效:
tell application "QuickTime Player"
-- don't use launch or activate
-- on my mac with launch I see a flicker of the window
set numberOfWindows to (count windows)
repeat with i from 1 to numberOfWindows
close front window
end repeat
end tell
-- may add some delay here if it still flickers the window
-- delay 1
tell application "QuickTime Player"
open URL "http://www.a-1radio.com/listen.pls"
set visible of every window to false
end tell
tell application "System Events"
set visible of process "QuickTime Player" to false
end tell
-- must be called after the open URL command or won't work (no idea why)
要关闭流,请退出或关闭窗口(如果您打算重新打开,则关闭):
tell application "QuickTime Player"
-- here you can either:
-- close all (will leave app open and hidden)
set numberOfWindows to (count windows)
repeat with i from 1 to numberOfWindows
close front window
end repeat
-- or:
quit -- or just quit (will close app so will need to hide again next time)
end tell
如果你在打开网址之前隐藏它,它就不起作用(不明白为什么)。当然,即使看不见的窗口仍然是打开的,所以如果有人点击停靠栏图标,它将显示所有打开的窗口。
如果您不想停止以前的流,请删除顶部的第一个repeat -- end repeat
部分,但保留无效的set numberOfWindows to (count windows)
,但无需激活/启动命令即可激活该应用