很久沒有上我愛吃蘋果,翻著翻著就找到JK.Chang大的 【分享】Applescript 快速縮圖
感覺這個想法一整個就好
因此一時手賤就去翻了一下原始的applescript
也寫了一個出來,當作練手
小是小但是功能不能少
當然要先感謝JK.Chang大和原作者robg
--
程式的名稱中只要有包含數字-無論前中後-便會抓取成為數值(沒有數值則會要求輸入)
-但是…如果名稱中的有兩組數字則會疊起來變成一個數值,如: 12temp34就會變成1234
-還有名稱太長的話可能會讀取得比較久
程式可以放置在任何位置
對中文支持
拖曳還是點選執行程式都可以使用,點選執行程式時則同樣可以複選處理
縮圖完的圖片選擇則和JK.Chang大和原作者robg一樣標示在前面
--底下是使用圖,都是拖曳縮圖的



附加壓縮檔: 200904/mobile01-b19f2e20d22c7051f0366631a2f8de80.zip
--
set tarFiles to choose file with multiple selections allowed without invisibles
main(tarFiles)
on open tarFiles
main(tarFiles)
end open
on main(tarFiles)
set pathMe to path to me
set myName to name of (info for pathMe)
set fileName to TrimExtn(myName)
set textNum to count fileName
set newPixel to getNumber(fileName, textNum)
if newPixel is false then set newPixel to text returned of (display dialog "newPixel" default answer "")
set tmp to "/tmp/"
repeat with tempFile in tarFiles
tell application "System Events" to set filePath to (path of (container of tempFile)) as Unicode text
set tempName to name of (info for tempFile)
set tmpPath to rescale_and_save(tempFile, newPixel, tmp)
do shell script "mv " & quoted form of tmpPath & " " & quoted form of (POSIX path of (filePath) & newPixel & "_" & tempName)
end repeat
end main
to rescale_and_save(this_item, newPixel, tmp)
set randomName to randomTexts() as string
tell application "Image Events"
launch
set the target_width to newPixel
-- open the image file
set this_image to open this_item
set typ to this_image's file type
copy dimensions of this_image to {current_width, current_height}
if current_width is greater than current_height then
scale this_image to size target_width
else
-- figure out new height
-- y2 = (y1 * x2) / x1
set the new_height to (current_height * target_width) / current_width
scale this_image to size new_height
end if
set newPath to tmp & randomName
tell application "Finder" to set new_item to newPath
save this_image in new_item as typ
end tell
return newPath
end rescale_and_save
on randomTexts()
set x to {}
repeat 10 times
set end of x to some item of "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
end repeat
return x
end randomTexts
on TrimExtn(fileName)
set savedDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to "." as Unicode text
set fileName to text item 1 of fileName as text
set AppleScript's text item delimiters to savedDelim
return fileName
end TrimExtn
on getNumber(fileName, textNum)
set newPixel to ""
repeat textNum times
repeat with i from 48 to 57
if (ASCII number (text item -1 of fileName)) = i then
set newPixel to (ASCII character i) & newPixel as string
exit repeat
end if
end repeat
try
set fileName to text items 1 thru -2 of fileName
on error
exit repeat
end try
end repeat
return newPixel as number
end getNumber




























































































