2010/1/22

設定開啟某資料夾時,iSight自動拍照



原文是Take a picture with the iSight camera when a folder is opened
我覺得還滿有趣的,於是自己測試了一下

首先在Libary資料夾根目錄底下新建一個名為UnixApps的資料夾
下載ImageSnap解壓縮之後將裡面的imagesnap放到剛剛新建的資料夾底下(所形成的路徑是 /Library/UnixApps/imagesnap)

打開AppleScript編寫程式(位於 /Applications/Utilities/) 將底下AppleScript 複製貼上到AppleScript編寫程式裡面後,另存檔案至 Library/Scripts/Folder Action Scripts folder底下,並且將檔案名稱取為open folder.scpt
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
之後選擇要設定的資料夾按右鍵 選擇檔案夾動作設定,之後在跳出的視窗選擇剛剛儲存的open folder.scpt


記得勾選左上角的啟動檔案夾動作,之後就可以將視窗關閉。

完成!

之後拍照的時候iSight旁邊的燈光依然會開啟,並且在拍完之後會自動關閉
照片會儲存在家目錄底下一個名為Seame的資料夾,但是在裡面只會看到一個SesameLog.txt檔案,他會記錄拍照的時間
例如
Fri Jan 22 03:29:17 CST 2010
Fri Jan 22 03:33:56 CST 2010
Fri Jan 22 21:26:31 CST 2010
至於照片也是儲存在這個資料夾裡面,不過預設是隱藏檔,要顯示隱藏的檔案有許多種方法
例如使用軟體TinkerTool
勾選第一個選項:Show hidden and system files之後按右下角的Relaunch Finder重啟Finder後就可以顯示所有的隱藏檔案
要回復的話就將第一個選項取消勾選在重啟Finder即可。
另外還有許多顯示隱藏檔的方法...
Posted in  on 21:45 by shizo |