I am trying to automate downloading videos from daillymotion using keepvid.com. If i execute the applescript below when my mouse is on a daily motion video link, then I reach the keepvid.com web page where i have two “Download” buttons: one for flv and other for mp4. I want to be able to click the “Download” button for mp4. I tried UIelement Inspector but i could not come up with anything. Any ideas?
tell application "System Events" to set frontProc to name of 1st process whose frontmost is true
if frontProc is "Safari" then
tell application "System Events"
tell process "Safari"
set StatusItem to 1st menu item of menu 1 of menu bar item 5 of menu bar 1 whose title contains "Status"
tell StatusItem to set StatusBarOff to its title contains "Show" or its title contains "ein"
if StatusBarOff then display dialog "Enable status bar in Safari and run script again" buttons {"Cancel"} default button 1
set theLink to value of static text 1 of group 1 of window 1
set theLink2 to text 8 thru -2 of theLink
tell application "Safari"
tell window 1
set theURL to "http://keepvid.com/?url=" & theLink2
set current tab to (make new tab with properties {URL:theURL})
end tell
end tell
end tell
end tell
end if
correction: i want to be able to control-click it, not click it because a “click” plays the video and does not download it.
If you could somehow tell me how to get the link of the “Download” button into applescript then i can use curl to download it.
I just control-clicked on “Download” button and then clicked “Inspect Element” to get the link. I passed the link to curl and it began downloading it.
How to get the link shown by “Inspect element” into applescript?
activate application "Safari"
tell application "System Events"
tell process "Safari"
set StatusItem to 1st menu item of menu 1 of menu bar item 5 of menu bar 1 whose title contains "Status"
tell StatusItem to set StatusBarOff to its title contains "Show" or its title contains "ein"
if StatusBarOff then display dialog "Enable status bar in Safari and run script again" buttons {"Cancel"} default button 1
set theLink to value of static text 1 of group 1 of window 1
set theLink2 to text 8 thru -2 of theLink
end tell
end tell
tell application "Safari"
tell window 1 to set current tab to make new tab with properties {URL:"http://keepvid.com/?url=" & theLink2}
if my page_loaded(20) is false then return
set num_links to (do JavaScript "document.links.length" in document 1)
set flag to false
repeat with i from 0 to num_links - 1
tell application "Safari" to set current_link to do JavaScript "document.links[" & i & "].href" in document 1
if current_link contains "h264" then -- eventually there a better pattern to distinguish the proper link
set flag to true
exit repeat
end if
end repeat
end tell
if flag then
set {TID, text item delimiters} to {text item delimiters, "/"}
set theName to last text item of current_link
set text item delimiters to TID
do shell script "/usr/bin/curl " & quoted form of current_link & " -o " & quoted form of (POSIX path of (path to desktop) & theName)
end if
on page_loaded(timeout_value) -- in seconds
repeat timeout_value times
tell application "System Events"
tell process "Safari"
set status to value of static text 1 of group 1 of window 1
if not (status begins with "Contacting" or status begins with "Loading") then return true
end tell
delay 1
end tell
end repeat
return false
end page_loaded
many thanks, StefanK. The script is working. The problem is that the program (Quicksilver or Butler) which i use to execute the applescript becomes inactive while the file is being downloaded. All my shortcuts(for launching applications, executing applescripts etc) created in Butler or Quicksilver become inactive.
Is there a particular way (or program) to use this script ? If i run it from the Scripts menu, I won’t be able to set up a keyboard shortcut to it.
do shell script "/usr/bin/curl " & quoted form of current_link & " -o " & quoted form of (POSIX path of (path to desktop) & theName) & " >/dev/null 2>&1 &"