As a Holiday Project, I am re-purposing an old macintosh as a Fake TV for my son to watch cartoons and things; it will simply be a monitor with no access to the controls, just like it’s showing a TV broadcast: turn it on, watch your program, and then it’s done; all you can do is turn off the “TV” and wait until tomorrow. Just like old times!
I have a mini2,1 (running MacOS 10.7.5) and I want to control it using iTunes (12.2.2.25) and AppleScript (2.4.3), with a schedule in iCal (5.0.3)
I want to use iTunes because of the simple organization, and playlists to manage files, plus i can just drop in movies and songs from my main computer.
I previously employed iCal as a playlist switcher, and it worked great.
However, i am making this more complicated…
For example, a playlist can fade mid-song and change audio. But you can’t switch off a Bugs Bunny cartoon half-way through, that would be a rotten trick.
An easy solution to that is a Smart Playlist, “limit to 30 Minutes” and it will self-populate with the right amount of cartoons–any leftover time can be filled with a “COMING UP NEXT!” card.
Finally, just to make it totally legit, i want to throw in a Station ID before each show or cartoon–just 6-second interstitials with a fake TV Logo, like a commercial break without any actual lousy commercial. This is purely for effect.
Phew! All that! and hopefully in time for Christmas!
in Pseudocode:
The current “DIY Dayparting” script follows.
--iCal event runs this AppleScript...
--Get Current Calendar Event via iCalBuddy hasseg.org/icalBuddy
set theEvent to {first item of my text_to_list((do shell script "/usr/local/bin/icalbuddy -eed -nc -b \"\" eventsNow"), return) as string}
--Use Calendar Event as Playlist Name
EvenlyShuffleThePlaylist(theEvent)
tell application "iTunes"
set full screen to true
play the playlist named "Now Playing"
end tell
--how do I know when the playlist is all done...?
--Use Calendar Event to determine "up next" loop
set theNextThing to (theEvent & "-Next.mp4")
set unixpath to "[path-to-up-next-folder]" & theNextThing
set macfile to (POSIX file unixpath)
tell application "QuickTime Player"
activate
delay 1
open file macfile
set looping of document 1 to true
set presenting of document 1 to true
play document 1
end tell
--EvenlyShuffleThePlaylist based on "CK's Evenly-shuffled Playlists v0.6" by Charles Kelly http://www.manythings.org/mac/
on EvenlyShuffleThePlaylist(thePlaylist)
set MergedPlayList to "Now Playing"
set PlaylistInterstitials to "[Interstitials]" -- this expects a playlist of the little station IDs, however many
set PlaylistTVShow to thePlaylist
tell application "iTunes"
-- get the playlist, creating it if necessary
if (every playlist whose name is MergedPlayList) is {} then
set MergedPlayList to make new user playlist with properties {name:MergedPlayList}
else
set MergedPlayList to user playlist MergedPlayList
end if
-- Define MergedTracks
set MergedTracks to every track of MergedPlayList
if (count of tracks of MergedPlayList) is 0 then
set MergedTracks to {}
else
-- If MergedTracks already has tunes, put those tunes into the list.
set MergedTracks to database ID of every track of MergedPlayList
end if
-- GET TRACKS FROM ALL LISTS
try
set allTracks01 to every file track of user playlist PlaylistInterstitials
set allTracks02 to every file track of user playlist PlaylistTVShow
on error
-- do nothing; an error will occur when a list does not exist.
end try
try
set x to (count of allTracks02)
on error
-- do nothing
end try
-- make the show
repeat with i from 1 to x
try
set theTrack to item i of allTracks01
set theTrackID to database ID of theTrack
if theTrackID is not in MergedTracks then
set enabled of (duplicate theTrack to MergedPlayList) to true
set MergedTracks to MergedTracks & (theTrackID)
end if
on error
-- do nothing
end try
try
set theTrack to item i of allTracks02
set theTrackID to database ID of theTrack
if theTrackID is not in MergedTracks then
set enabled of (duplicate theTrack to MergedPlayList) to true
set MergedTracks to MergedTracks & (theTrackID)
end if
on error
-- do nothing
end try
end repeat
end tell
end EvenlyShuffleThePlaylist
on text_to_list(txt, delim)
set saveD to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to {delim}
set theList to every text item of txt
on error errStr number errNum
set AppleScript's text item delimiters to saveD
error errStr number errNum
end try
set AppleScript's text item delimiters to saveD
return (theList)
end text_to_list
I’d welcome any suggestions or contributions, and I will post my progress here as I try to figure this out.