Applescript:如何讓 Podcasts 具備快進功能?

Podcasts Fastward AppleScript

最近突然愛上用Mac聽Podcasts,有時一聽就是整半天,不過節(jié)目中難免有一些段落或聽過的部分需要跳過,但iTunes又沒有快進功能,還好又讓小編遇到了一個解救技巧,那就是Applescript,這貨真的是無所不能,能夠控制Podcasts播放速度,還能調(diào)用具備快進/快退功能的Quicktime來播放Podcasts節(jié)目,來看腳本內(nèi)容:

tell application "iTunes"

    set setupNeeded to false

    --fetch prior selected playlist name and playback rate
    try
        set targetPlaylistName to do shell script "defaults read com.jeffporten.fastpodcast SelectedPlaylist"
        set playbackRate to do shell script "defaults read com.jeffporten.fastpodcast PlaybackRate"
    on error -- probably first run of script
        set setupNeeded to true
    end try

    if setupNeeded is false then -- confirm using last settings
        set userReply to button returned of (display dialog "Play playlist \"" & targetPlaylistName & "\" at " & playbackRate & " speed?" buttons {"Cancel", "Change...", "OK"} default button "OK")
        if userReply is "Change..." then set setupNeeded to true
    end if

    if setupNeeded is true then -- set up new settings
        set listPlaylists to the name of every playlist
        set targetPlaylistName to (choose from list listPlaylists with prompt "Which playlist to play?" without multiple selections allowed and empty selection allowed) as text
        set selectedSpeed to button returned of (display dialog "Playback rate to use?" & return & return & "(?X and 2X correspond to iPod playback speeds, actually 75% and 150%)" buttons {"Custom", "?X", "2X"})
        if selectedSpeed is "2X" then
            set playbackRate to 1.5
        else if selectedSpeed is "?X" then
            set playbackRate to 0.75
        else
            set playbackRate to text returned of (display dialog "Enter a playback speed. (1.0 is normal speed, 2.0 is true double-speed, 0.5 is true half-speed.)" default answer "1.0")
        end if
    end if

    --store settings in a non-AppleScripty way
    do shell script "defaults write com.jeffporten.fastpodcast SelectedPlaylist " & (quoted form of targetPlaylistName)
    do shell script "defaults write com.jeffporten.fastpodcast PlaybackRate " & (quoted form of (playbackRate as text))

    --actually do the playback in QuickTime Player
    set targetPlaylist to playlist targetPlaylistName
    set trackList to tracks of targetPlaylist
    repeat with i from 1 to count trackList
        set thisTrack to item i of trackList
        set podcastName to album of thisTrack
        set thisLoc to location of thisTrack
        set thisDuration to duration of thisTrack

        tell application "QuickTime Player"
            activate
            open thisLoc
            play document 1

            set rate of document 1 to playbackRate

            --if some podcasts should never be rate-altered, delete last line and use this instead
            --if (podcastName does not contain "Onion") then set rate of document 1 to 1.5

            --or for multiple podcasts, add as many of these as you like before "then set rate":
            --and (podcastName does not contain "someOtherPodcast") 

            set nextTrack to false
            set j to 0

            --if the QTP player is manually ended by dragging the slider to the end, automatically starts next podcast
            --if QTP player is closed, script errors out of existence
            --otherwise, when playback is finished, script will close the QuickTime Player document and open the next track in the playlist
            repeat until nextTrack is true
                delay 2
                if current time of document 1 ≥ duration of document 1 then set nextTrack to true
            end repeat

            close document 1
        end tell

        --mark the track as played
        set played count of thisTrack to (played count of thisTrack) + 1

        --I use this AppleScript line to set the rating of the podcast track to one star, which I delete later from a smart playlist
        --set rating of thisTrack to 20
    end repeat
end tell

粘入Applescipt,點擊“運行”

 

在第一個彈出框中選擇播放速度,有1/2X和2X兩種,分別是實際速度的75%和150%

 

或是選擇“Custom”自定義速度,中間會讓你選擇播放列表,選擇“Podcasts”即可,輸入以0.5為增量的數(shù)值可以定義自己需要的快進速度

 

確認點“OK”

 

定義的速度會立即通過Quicktime實現(xiàn),在恢復普通播放速度后,你還可以使用Quicktime的快進/快退鍵控制播放進程。

 

Podcasts Fastward AppleScript
評論