on opening folder this_folder     --finds out who is logged in   set myusername to do shell script "whoami"     --creates new folder for pic in home folder called Sesame   --easy to change name of folder by changing next line   set picFolder to "Sesame"   set HomeFolder to (path to current user folder)   tell application "Finder"     if not (exists folder picFolder of HomeFolder) then       make new folder at HomeFolder with properties {name:picFolder}     end if   end tell   set PhotoDirectory to ("/Users/" & myusername & "/" & picFolder)     --start by creating an original filename based on the date and time     -- Get the "hour"   set timeStr to time string of (current date)   set Pos to offset of ":" in timeStr   set theHour to characters 1 thru (Pos - 1) of timeStr as string   set timeStr to characters (Pos + 1) through end of timeStr as string     -- Get the "minute"   set Pos to offset of ":" in timeStr   set theMin to characters 1 thru (Pos - 1) of timeStr as string   set timeStr to characters (Pos + 1) through end of timeStr as string     --Get "day and date" and convert it to something usable   set DateStr to date string of (current date)   set Pos to offset of "," in DateStr   set theDay to characters 1 thru (Pos - 1) of DateStr as string   set theDATE to characters (Pos + 2) through end of DateStr as string     set Pos to offset of " " in theDATE   set theDayNumber to characters 1 thru (Pos - 1) of theDATE as string   set theMonthandYear to characters (Pos + 1) through end of theDATE as string     set Pos to offset of " " in theMonthandYear   set theMonth to characters 1 thru (Pos - 1) of theMonthandYear as string   set theyear to characters (Pos + 1) through end of theMonthandYear     -- set the file name     set TheFileName to (theDay & "_" & theDayNumber & "_" & theMonth & "_" & theyear & "_" & theHour & theMin)     -- take the photo   set SavePhoto to (PhotoDirectory & "/" & TheFileName & ".jpg")     --IMPORTANT COMMENT   --alter the following line if you have not saved imagesnap to UnixApps   set ImageSnapCommand to ("/Library/UnixApps/imagesnap" & " " & SavePhoto)   do shell script ImageSnapCommand     --create log file   do shell script "date >> " & PhotoDirectory & "/SesameLog.txt"   delay 10     --hide pic   do shell script "chflags hidden " & SavePhoto   end opening folder