Advertisement
Guest User

Untitled

a guest
May 25th, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 KB | None | 0 0
  1. tell application "iTunes"
  2.  
  3. set setupNeeded to false
  4.  
  5. --fetch prior selected playlist name and playback rate
  6. try
  7. set targetPlaylistName to do shell script "defaults read com.jeffporten.fastpodcast SelectedPlaylist"
  8. set playbackRate to do shell script "defaults read com.jeffporten.fastpodcast PlaybackRate"
  9. on error -- probably first run of script
  10. set setupNeeded to true
  11. end try
  12.  
  13. if setupNeeded is false then -- confirm using last settings
  14. set userReply to button returned of (display dialog "Play playlist \"" & targetPlaylistName & "\" at " & playbackRate & " speed?" buttons {"Cancel", "Change...", "OK"} default button "OK")
  15. if userReply is "Change..." then set setupNeeded to true
  16. end if
  17.  
  18. if setupNeeded is true then -- set up new settings
  19. set listPlaylists to the name of every playlist
  20. set targetPlaylistName to (choose from list listPlaylists with prompt "Which playlist to play?" without multiple selections allowed and empty selection allowed) as text
  21. 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"})
  22. if selectedSpeed is "2X" then
  23. set playbackRate to 1.5
  24. else if selectedSpeed is "½X" then
  25. set playbackRate to 0.75
  26. else
  27. 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")
  28. end if
  29. end if
  30.  
  31. --store settings in a non-AppleScripty way
  32. do shell script "defaults write com.jeffporten.fastpodcast SelectedPlaylist " & (quoted form of targetPlaylistName)
  33. do shell script "defaults write com.jeffporten.fastpodcast PlaybackRate " & (quoted form of (playbackRate as text))
  34.  
  35. --actually do the playback in QuickTime Player
  36. set targetPlaylist to playlist targetPlaylistName
  37. set trackList to tracks of targetPlaylist
  38. repeat with i from 1 to count trackList
  39. set thisTrack to item i of trackList
  40. set podcastName to album of thisTrack
  41. set thisLoc to location of thisTrack
  42. set thisDuration to duration of thisTrack
  43.  
  44. tell application "QuickTime Player"
  45. activate
  46. open thisLoc
  47. play document 1
  48.  
  49. set rate of document 1 to playbackRate
  50.  
  51. --if some podcasts should never be rate-altered, delete last line and use this instead
  52. --if (podcastName does not contain "Onion") then set rate of document 1 to 1.5
  53.  
  54. --or for multiple podcasts, add as many of these as you like before "then set rate":
  55. --and (podcastName does not contain "someOtherPodcast")
  56.  
  57. set nextTrack to false
  58. set j to 0
  59.  
  60. --if the QTP player is manually ended by dragging the slider to the end, automatically starts next podcast
  61. --if QTP player is closed, script errors out of existence
  62. --otherwise, when playback is finished, script will close the QuickTime Player document and open the next track in the playlist
  63. repeat until nextTrack is true
  64. delay 2
  65. if current time of document 1 ≥ duration of document 1 then set nextTrack to true
  66. end repeat
  67.  
  68. close document 1
  69. end tell
  70.  
  71. --mark the track as played
  72. set played count of thisTrack to (played count of thisTrack) + 1
  73.  
  74. --I use this AppleScript line to set the rating of the podcast track to one star, which I delete later from a smart playlist
  75. --set rating of thisTrack to 20
  76. end repeat
  77. end tell
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement