Custom spplit routine works great on it's own, dies when in a repeat

Total noob here, so be gentle. :smiley:

I’m trying to make use of kiwilegal’s script for automatically exporting recordings from EyeTV to .mp4 files found at http://bbs.applescript.net/viewtopic.php?pid=70501#p70501.

I need the files to be named in a very specific way though based on the time and date when they were recorded so I started work on my own code to pull the info from eyeTV to make the filename. To ease this, I’m making use of a routine I found written by jj at http://applescriptsourcebook.com/viewtopic.php?pid=46991 to emulates the split() function found elsewhere. It works great on it’s own but for some reason when I plug it in the middle of his/her repeat, I get

EyeTV got an error: Can’t continue split

Any ideas? Great heaps of appreciation for any assistance. Again, I’m wildly new to all of this, so please let me know if I’m doing something dumb.

Here’s the full script.



set destFolder to "scomhd:crs:encoded:"

--split subroutine provided by jj at applecriptsourcebook.com
to split(someText, delimiter)
	set AppleScript's text item delimiters to delimiter
	set someText to someText's text items
	set AppleScript's text item delimiters to {""} --> restore delimiters to default value
	return someText
end split

--Apple provided subroutine for replace_chars
on replace_chars(this_text, search_string, replacement_string)
	set AppleScript's text item delimiters to the search_string
	set the item_list to every text item of this_text
	set AppleScript's text item delimiters to the replacement_string
	set this_text to the item_list as string
	set AppleScript's text item delimiters to ""
	return this_text
end replace_chars

--Get MAC Address from Text File
set file_ref to open for access "scomhd:crs:macaddress.txt"
set macaddress to read file_ref
close file_ref

--Check if busy or recording. If not export using most recent settings from EyeTV Export.
tell application "EyeTV"
	set recordCount to count recordings
	if recordCount is greater than 0 then
		repeat
			delay 100
			set busyList to recordings whose busy is true
			if busyList is {} then exit repeat
		end repeat
		repeat with myCounter from 1 to count recordings
			set time_stamp to start time of item myCounter of recordings
			
			--split into array
			set dateformat_array to split(time_stamp, space)
			
			set split_dayname to item 1 of dateformat_array
			set split_month to item 2 of dateformat_array
			set split_day to item 3 of dateformat_array
			set split_year to item 4 of dateformat_array
			set split_time to item 5 of dateformat_array
			set split_AMPM to item 6 of dateformat_array
			
			--reformat individual elements
			--drop comma on day
			set split_day to replace_chars(split_day, ",", "")
			
			--convert month to number
			set the split_month to replace_chars(split_month, "January", "01")
			set the split_month to replace_chars(split_month, "February", "02")
			set the split_month to replace_chars(split_month, "March", "03")
			set the split_month to replace_chars(split_month, "April", "04")
			set the split_month to replace_chars(split_month, "May ", "05")
			set the split_month to replace_chars(split_month, "June", "06")
			set the split_month to replace_chars(split_month, "July", "07")
			set the split_month to replace_chars(split_month, "August", "08")
			set the split_month to replace_chars(split_month, "September", "09")
			set the split_month to replace_chars(split_month, "October", "10")
			set the split_month to replace_chars(split_month, "November", "11")
			set the split_month to replace_chars(split_month, "December", "12")
			
			--add leading zero to day
			set split_day to text -2 thru -1 of ("00" & split_day)
			
			--remove colons from time
			set the split_time to replace_chars(split_time, ":", "-")
			
			--put it all together
			set reformated_timestamp to split_year & split_month & split_day & "_" & split_time & "_" & split_AMPM
			
			--Export Files
			export from item myCounter of recordings to file (destFolder & macaddress & reformated_timestamp & "_800k.mp4") as MPEG4 replacing yes
			export from item myCounter of recordings to file (destFolder & macaddress & reformated_timestamp & "_300k.mp4") as iPodMP4 replacing yes
		end repeat
		repeat
			delay 100
			set busyList to recordings whose busy is true
			if busyList is {} then exit repeat
		end repeat
		delete recordings
	end if
end tell

Can you show us what a typical time_stamp looks like? There are much easier ways to get what I think you want.

Sure. EyeTV gives me this as the start date.

Tuesday, December 5, 2006 2:32:15 PM

Ultimately, what I want to do is name the corresponding file using this and the MAC address. So if this were coming off of a machine with the MAC address of 1a:1a:1a:1a:1a:1a I’d want 2 files (for the two different export formats) with the final file names to be

1a1a1a1a1a1a_20061205_2-32-15PM_300k.mp4
1a1a1a1a1a1a_20061205_2-32-15PM_800k.mp4

If your easier way includes a simple conversion to a 24 hour time format, I’d be interested in that too, but it’s not a big deal and seemed more trouble than it was worth with the way I was doing it.

Thanks for taking the time to help me out.

Adam,
So I read your article on formating time and dates and my goodness yes that is quite a bit simpler. I don’t have access to EyeTV at home here so I can’t test it, but I thought I’d go ahead and post my new script just so we’re on the same page.


set destFolder to "scomhd:crs:encoded:"

--date subroutine provided by adam bell at macscripter.net
to date_format(old_date) -- Old_date is text, not a date.
	set {year:y, month:m, day:d} to date old_date
	tell (y * 10000 + m * 100 + d) as string to text 1 thru 4 & "." & text 5 thru 6 & "." & text 7 thru 8
end date_format

--Get MAC Address from Text File
set file_ref to open for access "scomhd:crs:macaddress.txt"
set macaddress to read file_ref
close file_ref

--Check if busy or recording. If not export using most recent settings from EyeTV Export.
tell application "EyeTV"
   set recordCount to count recordings
   if recordCount is greater than 0 then
       repeat
           delay 100
           set busyList to recordings whose busy is true
           if busyList is {} then exit repeat
       end repeat
       repeat with myCounter from 1 to count recordings
           set time_stamp to start time of item myCounter of recordings
			
			--Format Time
			set dateformat_array to words of time_stamp

			set split_hour to item 5 of dateformat_array
			set split_minute to item 6 of dateformat_array
			set split_second to item 7 of dateformat_array
			set split_AMPM to item 8 of dateformat_array

			set formated_time to split_hour & "-" & split_minute & "-" & split_second & "-" & split_AMPM 
			
			set formated_date to date_format(time_stamp)
			          
           --Export Files
           export from item myCounter of recordings to file (destFolder & macaddress & "_" & formated_date & "_" & formated_time & "_300k.mp4") as MPEG4 replacing yes
           export from item myCounter of recordings to file (destFolder & macaddress & "_" & formated_date & "_" & formated_time & "_800k.mp4") as iPodMP4 replacing yes
       end repeat
       repeat
           delay 100
           set busyList to recordings whose busy is true
           if busyList is {} then exit repeat
       end repeat
       delete recordings
   end if
end tell

I’ll post in the morning if this fixes my problem.

Hi grovberg,

if you need the MAC address of the current machine, use the shell script line below.
Date and time formatting can be simplified a bit

set destFolder to "scomhd:crs:encoded:"
(*
	-Get MAC Address from Text File
	set file_ref to open for access "scomhd:crs:macaddress.txt"
	set macaddress to read file_ref
	close file_ref
*)
-- a simple way to get the MAC-address of this machine
set macaddress to words 2 thru 7 of (do shell script "ifconfig en0 ether | grep -i ether" as string) as string

--Check if busy or recording. If not export using most recent settings from EyeTV Export.
tell application "EyeTV"
	set recordCount to count recordings
	if recordCount is greater than 0 then
		repeat
			set busyList to recordings whose busy is true
			if busyList is {} then exit repeat
			delay 100
		end repeat
		repeat with myCounter from 1 to count recordings
			set recording_date to start time of item myCounter of recordings
			set {yr, mo, dy, hr, mn, sc} to {year, month, day, hours, minutes, seconds} of recording_date
			set formated_date to (yr * 10000 + (mo as number) * 100 + (text -2 thru -1 of ("0" & dy) as number)) as string
			set formated_time to text -2 thru -1 of ("0" & hr) & "-" & mn & "-" & sc -- 24hr format
			--Export Files
			export from item myCounter of recordings to file (destFolder & macaddress & "_" & formated_date & "_" & formated_time & "_300k.mp4") as MPEG4 replacing yes
			export from item myCounter of recordings to file (destFolder & macaddress & "_" & formated_date & "_" & formated_time & "_800k.mp4") as iPodMP4 replacing yes
		end repeat
		repeat
			delay 100
			set busyList to recordings whose busy is true
			if busyList is {} then exit repeat
		end repeat
		delete recordings
	end if
end tell

Bless you for your kindness. This is even better.


(*
   -Get MAC Address from Text File
   set file_ref to open for access "scomhd:crs:macaddress.txt"
   set macaddress to read file_ref
   close file_ref
*)
-- a simple way to get the MAC-address of this machine
set macaddress to words 2 thru 7 of (do shell script "ifconfig en0 ether | grep -i ether" as string) as string

Hilariously enough, this is exactly what I’m doing, just in another script. Since the MAC address isn’t going to change, I just have another script run once at launch and store in the info in a text file, because this script we’re working on here is going to run every twenty minutes or so.

The date formating you added works perfectly though, so many thanks to you on that one. I do have one more error though.


       repeat
           delay 100
           set busyList to recordings whose busy is true
           if busyList is {} then exit repeat
       end repeat
       delete recordings

I got an error at delete recordings because it says one of the items is busy. My guess is that the script sneaked through in between it processing two of the files (ie file finished exporting, script checked for busy and saw nothing was busy so it moved on, then the next file started processing).

So I see two options.

1.) Modify the script so it deletes the recordings one at a time after it finishes recording. This actually seems safer anyway, so is there any reason I shouldn’t just do that anyway right after the export?

2.) Since I’m gonna have the script run pretty regularly throughout the day anyway, is there a way I could just suppress the error so that the script runs merrily on it’s way and would just pick it up on the next go around?

Thanks again for all the help. This site is a godsend.

Yes, a try block avoids error messages

try
delete recordings
end try