Trim podcasts intros with AppleScript

Jul 12, '12 07:30:00AM

Contributed by: kopurando

Many podcasts feature a lengthy intro that you have to hear every time you listen to a podcast. If you, like me, listen to fresh news podcasts every morning, you have to skip introductions manually just to get to the news section. Wouldn't it be nice if podcasts were trimmed automagically? Here's the AppleScript for that.

The script is based on Doug Adams' Reset Tracks Start script (GNU GPL). My version of his script goes through every track in a playlist and sets track start time to 90 seconds (you can adjust this number to suit your needs). "News" is the name of my playlist; change accordingly.

property my_title : "Trim all tracks in a playlist"
tell application "iTunes"
	set thePlaylist to playlist "News"
	with timeout of 300 seconds
		repeat with i from 1 to (index of last track of thePlaylist)
			my reset_this(track i of thePlaylist)
		end repeat
	end timeout
end tell

to reset_this(t)
	tell application "iTunes"
		try
			set start of t to 90.0
		on error m
			log m
		end try
	end tell
end reset_this

I use crontab to run this script every morning, but you can use iCal:

  1. Create a recurring event (every morning at 7 am, for example)
  2. Choose Alarm and select Run Script, locate the script file you've just created
Now, every morning at 7 am the script will quetly run and "trim" all the tracks in News playlist to make your mornings a little bit more efficient.

NB: "trimming" does NOT actually trim your tracks, it merely adjusts the starting point; this is totally reversible and instantaneous. If you want to undo this, just change 90.0 to 0.0 and re-run the script.

[kirkmc adds: This is sweet. The only problem is that different podcasts have different length intros. So what I'm going to do is make a number of scripts with different offset times and run them on selected podcasts, adding the podcasts as I want to a playlist on which the script acts. I asked Doug Adams how to change this script so it acts on a selection rather than a playlist. He said to use the following:
property my_title : "Trim all tracks in a playlist"
tell application "iTunes"
	set theSelection to selection
	with timeout of 300 seconds
		repeat with aTrack in theSelection
			my reset_this(aTrack)
		end repeat
	end timeout
end tell

to reset_this(t)
	tell application "iTunes"
		try
			set start of t to 90.0
		on error m
			log m
		end try
	end tell
end reset_this

You'll notice that only o couple if lines in the first part of the script are changed.]

Comments (3)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20120705014936126