Skip to content

Instantly share code, notes, and snippets.

@cmittendorf
Last active August 29, 2015 14:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmittendorf/14ebe95e6456c378ec7c to your computer and use it in GitHub Desktop.
Save cmittendorf/14ebe95e6456c378ec7c to your computer and use it in GitHub Desktop.
This AppleScript will allow you to select a WWDC 2014 video and open it automatically using the QuickTime 7 player (http://support.apple.com/kb/DL923) allowing you to increase the playback speed as mentioned in BitsUndSo episode #379 (http://www.bitsundso.de/bus379/). Be aware that the script does not check if the QT7 player is already installed.
(***
Use this AppleScript to launch WWDC 2014 videos in QuickTime Player 7, where
you can adjust the playback speed to your needs (⌘ + k). Have fun!
Christian Mittendorf, 15.06.2014
cmittendorf<et>me.com
***)
set page_url to "https://developer.apple.com/videos/wwdc/2014/"
set videos to missing value
tell application "Safari"
activate
if number of documents is 0 or URL of front document is not page_url then
open location page_url
delay 1
end if
tell front document
set page_load_done to false
repeat until page_load_done
delay 1
set page_load_state to do JavaScript "document.readyState"
if page_load_state is equal to "complete" then
set page_load_done to true
end if
end repeat
set videos to do JavaScript ("var getVideos = function() {
var sessions = document.getElementsByClassName('session');
var titles = new Array();
var hd_urls = new Array();
for ( var i = 0; i < sessions.length; i++) {
var session = sessions[i];
var title = session.getElementsByClassName('title')[0].textContent;
var track = session.getElementsByClassName('track')[0].textContent;
var platform = session.getElementsByClassName('platform')[0].textContent;
var track_name = title + ' (' + track + ', ' + platform + ')';
var download = session.getElementsByClassName('download')[0].getElementsByTagName('a');
var track_hd_url = null;
if (download.length > 0) {
track_hd_url = download[0].href;
}
titles.push(track_name);
hd_urls.push(track_hd_url);
}
var result = new Array();
result.push(titles);
result.push(hd_urls);
return result;
};
getVideos();")
end tell
end tell
activate
set result to choose from list item 1 of videos with title "WWDC Videos" with prompt "Select Video to open" default items {} without multiple selections allowed
if result is not false then
set idx to my list_position(item 1 of result, item 1 of videos)
if idx > 0 then
set video_url to item idx of item 2 of videos
tell application "QuickTime Player 7"
activate
getURL video_url
end tell
end if
end if
on list_position(this_item, this_list)
repeat with i from 1 to the count of items in this_list
if item i of this_list is equal to this_item then return i
end repeat
return 0
end list_position
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment