Skip to content

Instantly share code, notes, and snippets.

@kylemcdonald
Created June 25, 2014 23:40
Show Gist options
  • Save kylemcdonald/f7c8f8c9267fe1b310a9 to your computer and use it in GitHub Desktop.
Save kylemcdonald/f7c8f8c9267fe1b310a9 to your computer and use it in GitHub Desktop.
Records video from your webcam whenever you are visiting a specific site.
global targetDomain
global folderName
-- options
set targetDomain to "dropcam.com"
set folderName to (path to desktop as text) & "Dropcam"
-- main code
global recordingFile
global newMovieRecording
on startRecording(filePath)
set recordingFile to a reference to file filePath
tell application "QuickTime Player"
set newMovieRecording to new movie recording
tell newMovieRecording
start
end tell
end tell
end startRecording
on stopRecording()
tell application "QuickTime Player"
tell newMovieRecording
pause
save newMovieRecording in recordingFile
stop
close newMovieRecording
end tell
end tell
end stopRecording
on checkSite()
tell application "Google Chrome"
repeat with win in windows
set curUrl to URL of active tab of win
if curUrl contains targetDomain then
return true
end if
end repeat
return false
end tell
end checkSite
on getTimestamp(now)
set stamp to {¬
year of now, "-", ¬
month of now, "-", ¬
day of now, " ", ¬
hours of now, " ", ¬
minutes of now, " ", ¬
seconds of now}
return stamp as string
end getTimestamp
global moviePath
global recordingStatus
global startTime
set recordingStatus to false
on update()
set siteStatus to checkSite()
log siteStatus
if siteStatus then
if not recordingStatus then
set recordingStatus to true
set startTime to current date
set moviePath to folderName & ":" & getTimestamp(startTime)
log moviePath
startRecording(moviePath & ".mov")
end if
else if recordingStatus then
set recordingStatus to false
stopRecording()
set duration to (current date) - startTime
set beforeName to moviePath & ".mov"
set afterName to getTimestamp(startTime) & " +" & duration & ".mov"
tell application "Finder"
set the name of file beforeName to afterName
end tell
end if
end update
-- infinite loop
repeat
update()
delay 1
end repeat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment