-- ARD Snap
-- A script to retrieve an image from the default iSight camera of the remote client's machine.
-- The retrieved image is copied to the admin's desktop and named <MachineName>-<UserName>-<Date><Time>.jpg
-- No indication is given to the client except the iSight camera light turns on momentarily.
-- Use at your own risk
-- Requirements:
-- Script expects "imagesnap" to be installed at /usr/local/bin on the client machine. Imagesnap is available from
-- http://iharder.sourceforge.net/current/macosx/imagesnap/
-- This has been tested on Mac OS X.6.8, Remote Desktop 3.4 & 3.5.1, Applescript 2.1.2
-- Works on a client machine from both the login screen and when a user is logged in.
-- Notes:
-- "/dev/null" is used on the shell command since imagesnap reports errors in some cases but still works.
-- Distribute as you wish
-- August 2011 - JM
set dateStamp to dateString(current date)
set myPath to (path to home folder) as string
tell application "Remote Desktop"
--set theScript to "/usr/sbin/screencapture -x -T 0 -t jpg /tmp/snap.jpg" --Do a screen capture (fails if no user logged in)
set theScript to "/usr/local/bin/imagesnap /tmp/snap.jpg 1>/dev/null 2>/dev/null" --Do an isight capture
set theClients to the selection
repeat with x in theClients
set theTask1 to make new send unix command task with properties {showing output:true, user:"root", script:theScript} --build the task
set theTaskResult to execute theTask1 on x
set theTask2 to make new copy to me task with properties {copy items:{"/tmp/snap.jpg"}, location:current users desktop folder, conflict resolution:replace}
set theTaskResult to execute theTask2 on x
set theUser to current user of x
set theName to name of x
tell application "Finder"
set the name of file (myPath & "Desktop:snap.jpg") to (theName & "-" & theUser & " " & dateStamp & ".jpg")
end tell
end repeat
end tell
on dateString(theDate)
set {year:theYear, time string:theTime, short date string:shortDate} to theDate
set {theMonth, theDay} to {word 1, word 2} of shortDate -- Use for US Date format
-- set {theDay, theMonth} to {word 1, word 2} of shortDate -- Use for International date format
set {HH, MM, ss} to {word 1, word 2, word 3} of theTime
set HH to HH as integer
if HH < 10 then set HH to "0" & HH
return (theYear as text) & "-" & theMonth & "-" & theDay & " " & HH & "-" & MM & "-" & ss
end dateString