Skip to content

Instantly share code, notes, and snippets.

@Coro365
Last active February 26, 2016 13:00
Show Gist options
  • Save Coro365/d2bf3e475134b8442950 to your computer and use it in GitHub Desktop.
Save Coro365/d2bf3e475134b8442950 to your computer and use it in GitHub Desktop.
This applescript will automatically play the episode of the next iTunes TV show.
--Version 20150808
--This applescript will automatically play the episode of the next iTunes TV show.
--Please select Japanese or English. (comment out "--")
--Please export application format. (File > Export > File type > Application > Save)
--This version does not support the jump from the last episode to within three minutes of the place.
--Author is coro (http://coro3.net)
on run {}
tell application "iTunes" to activate
repeat
log "Waiting play TV Show...(Play check after 20s)"
delay 20
tell application "iTunes"
set videoKind to ""
try
set videoKind to video kind of current track
end try
if videoKind = TV show then
--Notification
tell application "Script Editor"
display notification "再生中のTV Showを検出" & return & "再生位置の監視を開始します" with title "goNextEpisode"
--display notification "Found playing TV Show" & return & "Start player position trace" with title "goNextEpisode"
end tell
monitoring() of me
end if
end tell
end repeat
end run
on monitoring()
log "Strat monitoring"
repeat
set timeSize to getTimeSize()
set nowTime to getNowTime()
if (timeSize - nowTime) > 180 then
set wait to 179
else if (timeSize - nowTime) > 60 then
set wait to 59
else if (timeSize - nowTime) > 1 then
set wait to 1
else if (timeSize - nowTime) < 1 then
tell application "iTunes"
next track
--Checking play success
set videoKind to ""
try
set videoKind to video kind of current track
on error
--Notification
tell application "Script Editor"
display notification "最後の再生でした Scriptを終了します" & return & "Have a nice day!" with title "goNextEpisode"
--display notification "Last episode. Quit script" & return & "Have a nice day!" with title "goNextEpisode"
end tell
error number -128
end try
--Notification
tell application "Script Editor"
display notification "次のEpisodeです" with title "goNextEpisode"
--display notification "Next is episode" with title "goNextEpisode"
end tell
end tell
end if
log "Waiting. Next check after " & wait & "s"
delay wait
end repeat
end monitoring
on getTimeSize()
tell application "iTunes"
try
set timeSize to time of current track as text
on error
log "iTunes has finished playing(Can't get size time)"
--Notification
tell application "Script Editor"
display notification "再生を見失いました" & return & "Scriptを終了します" with title "goNextEpisode"
--display notification "We lost sight of Play" & return & "Quit script" with title "goNextEpisode"
end tell
error number -128
end try
set AppleScript's text item delimiters to {":"}
set timeSize_l to text items of timeSize
try
--Over 1hour
set hur to item 1 of timeSize_l
set min to item 2 of timeSize_l
set sec to item 3 of timeSize_l
return (hur * 60 * 60) + (min * 60) + sec
on error
--Under 1hour
set min to item 1 of timeSize_l
set sec to item 2 of timeSize_l
return (min * 60) + sec
end try
end tell
end getTimeSize
on getNowTime()
tell application "iTunes"
set nowPositionSec to player position
if nowPositionSec = missing value then
log "iTunes has finished playing(Can't get now time)"
--Notification
tell application "Script Editor"
display notification "再生を見失いました" & return & "Scriptを終了します" with title "goNextEpisode"
--display notification "We lost sight of Play" & return & "Quit script" with title "goNextEpisode"
end tell
error number -128
end if
return nowPositionSec
end tell
end getNowTime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment