First post from a first time scripter, so all apologies…
First let me explain what I hope for this script to ultimately do. We are going to use NicePlayer (a movie player) to run playlists in to a video encoder which in turn feeds our networks desktop video. Each video in the playlist is triggered to play by a script that is in turn triggered by an event in iCal. This way we can say that a articular video will be playing at a set time. That part works fine.
What I’m trying to build now is a script that will make everything relatively automated so my staff can simply select the videos for the day and the start time. As it is now, you select the bumper (a slate that will fill out dead time to the next half hour when the next video will start) and then the movies for the day. Once all the videos are selected, the user is asked to select the start time (default 8AM). A new event is then created for each movie, starting after the previous one, rounded to the nearest half hour. That part works fine too.
Here’s where I run into trouble. We want programming to run from 8AM to midnight. We’re not going to have 16 hours of unique videos, more like 4 to 6 hours that will repeat throughout. What I want to do is create events to fill out the day based on the first pass. For instance, after the first four hours, it will keep repeating those same events until midnight. However, when I do any form of “repeat until end time of end time is greater than or equal to 11:30 PM” it either gives an error or goes into an infinite loop. It keeps adding the events in the exact order I want, but it won’t stop adding them. Does this make sense? Please, I’ve been banging my head against the wall for the last day on this and am finally admitting defeat.
Script follows (as it is now, it does not include the unwanted infinite repeat loop):
tell application "NicePlayer"
--Promt the user to select the files for the bumper and other movies to be played
tell playlist of front window
add (choose file with prompt "Select the BUMPER:") to playlist of front window
set playlist is showing of front window to true
try
repeat
tell playlist of front window
add (choose file with prompt "Select the next movie or hit Cancel:") to playlist of front window
end tell
end repeat
end try
end tell
end tell
--Create iCal events for each movie based on user input
tell application "NicePlayer"
tell front playlist
set TheIndex to index of current movie
end tell
end tell
--confirms 8:00 AM of the current day as the start time of programming
set DefaultTime to "8:00:00 AM"
activate
set StartDateQuery to (display dialog "What day would you like this program to play?" default answer (date string of ((current date))))
set startdate to date (text returned of StartDateQuery)
set StartTimeQuery to (display dialog "What time (24-hour format) would you like this program to start?" default answer DefaultTime)
set StartTime to date (text returned of StartTimeQuery)
set EventStart to date (time string of StartTime) of startdate
--creates iCal event on current day (unless changed) starting at 8:00 AM with the next event starting after the prior one ended (to the nearest half hour).
try
repeat
tell application "NicePlayer"
tell front playlist
set IndexIncrease to TheIndex + 1
set TheIndex to IndexIncrease
set ThePath to path of movie index (TheIndex)
tell application "System Events"
set EventDuration to (((duration of contents of movie file ThePath) / (time scale of contents of movie file ThePath))) / hours
if (EventDuration mod 0.5 > 0.0) then set EventDuration to (EventDuration + 0.5) div 0.5 * 0.5
end tell
set TheSummary to name of movie index TheIndex
end tell
end tell
tell application "iCal"
tell calendar "TV Schedule"
make new event at end with properties {summary:TheSummary, start date:EventStart, end date:(EventStart + (EventDuration * hours)), allday event:false}
end tell
end tell
--reset "EventStart" to end of last event
set DefaultTime to time string of (EventStart + (EventDuration * hours))
set EventStart to date DefaultTime
end repeat
end try
Again, this is my first script I’ve written, so if something else looks glaringly wrong or uneffective, please let me know.
Thanks,
Mike
Model: Mac Pro Dual Core Xeon
AppleScript: 2.1.1
Browser: Safari 419.3
Operating System: Mac OS X (10.4)