2013-08-18 34 views
0

我的品牌新的AppleScript,我想寫執行以下一個基本的腳本:的AppleScript:組織基於圖像尺寸圖像

文件夾〜/ Dropbox的/相機在查找圖像(PNG格式)上傳完全是640x1136(iPhone 5屏幕截圖)並將其移至〜/ Dropbox /相機上傳/屏幕截圖。

這看起來很簡單,但到目前爲止我還沒有弄明白。

回答

2

這是我會怎麼做。我不會擔心表演。我在200個文件上運行了圖像事件部分,只花了1秒。

set picFolder to alias "Path:to:Dropbox:Camera Uploads:" 
set screenshotFolder to alias "Path:to:Dropbox:Camera Uploads:screenshots:" 


tell application "System Events" 
    set photos to path of files of picFolder whose kind is "Portable Network Graphics image" 
end tell 

set screenshots to {} 
repeat with imgPath in photos 
    set imgAlias to alias imgPath 
    tell application "Image Events" 
     set img to open imgPath 
     if dimensions of img = {640, 1136} then 
      set end of screenshots to imgAlias 
     end if 
     close img 
    end tell 
end repeat 

tell application "Finder" 
    move screenshots to screenshotFolder 
end tell 
+0

我收到錯誤:「變量圖片未定義。」 – colindunn

+0

我清理腳本後發生了錯字。我編輯過它。現在就試試。 –

+0

嗯。現在,我將「應用程序」Image Events「的Macintosh HD:用戶:colind:Dropbox:相機上傳:2013-08-21 12.19.04.png」變爲預期類型。「 – colindunn

0

您需要有一個AppleScript感知應用程序,可以根據圖像文件的尺寸進行操作。我不認爲Finder可以做到這一點,儘管它能夠在Finder視圖中顯示圖像的尺寸。

iPhoto應該可以做到這一點。 iPhoto詞典表示「照片」具有圖像的寬度和高度。所以你應該可以編寫一個AppleScript,將它們先導入到iPhoto中,然後選擇符合條件的文件,然後將它們保存到相應的Dropbox文件夾中。

根據您的需要,您也可以查看Automator。它還包含iPhoto操作,其中包括一個用於「過濾iPhoto項目」的操作。如果您創建文件夾操作,則應該能夠創建一個Automator腳本,該腳本在新增功能添加到相機上傳文件夾時啓動,並將其添加到iPhoto,然後將其複製到屏幕截圖文件夾。

如果沒有其他內容,您應該可以使用圖像事件在文件夾中獲取所有圖像,然後僅處理符合條件的圖像。喜歡的東西:

tell application "Image Events" 
    tell folder "Macintosh HD:Users:colin:Dropbox:Camera Uploads" 
     copy (files where kind is "JPEG image") to potentialScreenshots 
     repeat with potentialFile in potentialScreenshots 
      set potentialScreenshot to open potentialFile 
      set imageDimensions to dimensions of potentialScreenshot 
      if item 1 of imageDimensions is 640 then 
       set fileName to name of potentialFile 
       tell me to display dialog fileName 
      end if 
     end repeat 
    end tell 
end tell 

有應該是一個方式告訴圖像事件只查找文件,其尺寸符合你想要什麼,但我不能看到它。

+0

尺寸可通過Finder'Get Info'窗口訪問,所以應該有一種方法可以在不打開每個圖像的情況下獲取它們。儘管除此之外,你可以使用Bash的'file'命令。不應該需要打開所有正在檢查的文件(特別是如果OP有100多個) – scohe001

0

嘗試:

set folderPath to POSIX path of (path to home folder) & "Dropbox/Camera Uploads" 
set screenshotsPath to POSIX path of (path to home folder) & "Dropbox/Camera Uploads/Screenshots" 

try 
    do shell script "mdfind -0 -onlyin " & quoted form of folderPath & " \"kMDItemPixelWidth == 640 && kMDItemPixelHeight == 1136\" | xargs -0 -I {} mv {} " & quoted form of screenshotsPath 
end try