2014-05-18 180 views
1

我正在從FilemakerPro中調用Applescript。 這些都是我儘量做到的事情:AppleScript調整圖像大小並以新名稱保存

  • 的圖像存儲在容器字段中。
  • 它將其名稱和路徑存儲在單獨的字段中。

一個AppleScript被激活以執行以下操作:

  • 它從FilemakerPro檢索數據
  • 它檢查是否存在具有相同名稱的字段「calculate_merk_id」
  • 的文件夾
  • 如果不是,它會創建文件夾
  • 它會創建一個新的圖像文件,該圖像文件的名稱在調整爲155 x 134後應將「__small」添加到其名稱中,並將其存儲在此文件夾中
  • 它創建該文件夾中的一個新的鏡像文件應該有其名「__large補充說:」以他的名字已經調整到400×400後,並將其存儲

我收到的第一個錯誤是,它無法檢索圖像的尺寸。此外,它不會創建我調整大小的圖像...任何人想要給我一個正確的方向,請好嗎?

set pad to cell "ServerImagePath" of current record 
set filenaam to cell "afbeelding_local_vol_pad" of current record 
set foldernaam to cell "calculate_merk_id" of current record 
set volle_foldernaam to cell "ServerImageFolder" of current record 
set volle_filenaam to cell "ServerImageFile" of current record 

set target_small_width to 155 
set target_small_height to 134 
set target_large_width to 400 
set target_large_height to 400 

tell application "Finder" 
if not exists volle_foldernaam then 
      make new folder at pad with properties {name: foldernaam} 
    end if 

    duplicate filenaam to volle_foldernaam with replacing 

    tell application "Image Events" 
     launch 
     set this_image to filenaam 
     copy dimensions of this_image to {W, H} 

     if target_small_width is greater than target_small_height then 

     if W is greater than H then 

      set the scale_length to (W * target_small_height)/H 
      set the scale_length to round scale_length rounding as taught in school 
     else 

      set the scale_length to target_small_height 
      end if 

     else if target_small_height is greater than target_small_width then 

      if H is greater than W then 

      set the scale_length to (H * target_small_with)/W 
      set the scale length to round scale_length rounding as taught in school 
      else 

      set the scale_length to target_small_width 
      end if 

     else 
      set the scale_length to target_small_height 
     end if 

     scale this_image to size scale_length 

     pad this_image to dimensions {target_small_width, target_small_height} 


     save this_image as this_name & "__small" 

     close this_image 

    end tell 

end tell 
+0

@ mklement0你改變了什麼?格式仍然是錯誤的,標題中有一個標籤。 – Mark

+0

@Mark:我將「Apple腳本」更改爲「AppleScript」,因爲這是技術和腳本實例的名稱,就像這種情況一樣。 (一般來說:如果標題與標題密切相關,則標題中的標記沒有任何問題)。之前沒有語法突出顯示,所以我添加了<! - language:lang-applescript - >';請注意,雖然AppleScript未得到正式支持,因此突出顯示有時不正確,但仍然最好不要突出顯示。這是你引用的格式錯誤嗎? – mklement0

+0

不,縮進有點小,AFAIK根據指南不應該在標題中加標籤(但這些標籤可能會發生變化,我可能會落後)。 – Mark

回答

0

你忘了打開圖像

set this_image to filenaam 

應該

set this_image to open filenaam 
+0

然後它失敗並出現一個錯誤:缺失值的尺寸可以不會被檢索到... –

+0

它看起來像變量filenaam不正確。嘗試'log filenaam'。這是一個正確的文件路徑嗎? – user309603

+0

日誌存儲在哪裏?如果我使用 將this_image設置爲filenaam 它顯示了正確的文件 –

0

爲什麼的FileMaker不能做到這一點本身? FM 12和更高版本具有GetThumbnail()函數。腳本可以將重新調整大小的圖像計算爲全局字段,然後從全局字段中導出圖像。完全跨平臺將可用於OSX和Windows,甚至FileMaker Go。

Set Field [ photo_temp_g ; GetThumbnail (photo_original ; width ; height) ] 
Commit Record/Request [] 
Export Field Contents [ photo_temp_g ; 「<filename>」 ] 
相關問題