[英]AppleScript Droplet to Convert PSD and TIF to JPG
有很多轉換為 JPG 的示例,我正在嘗試根據我的需要更改一個,但我需要的幫助很少。 要求是:
我知道圖像事件允許我們設置 JPG 壓縮,例如:
save openedFile as JPEG with compression level (low|medium|high)
但不幸的是我需要更多的定制。
shell 腳本將幫助我將級別設置為 10 到 100,但不幸的是我無法正確實現 shell 腳本。 請對第 3 點和第 4 點提供一點幫助。謝謝!
on run
display dialog "Please drag image files to this script to turn them into JPEGs"
end run
on open draggeditems
set End_Folder to "Macintosh HD:Users:zzz:Desktop:End"
repeat with currentFile in draggeditems
tell application "Image Events"
set openedFile to open (currentFile as alias)
set fileLocation to the location of openedFile
set fileName to the name of openedFile
set Path_to_Converted_File to (End_Folder & ":" & text 1 thru -5 of fileName & ".jpg")
do shell script "sips --setProperty formatOptions 10 " & openedFile
save openedFile as JPEG in Path_to_Converted_File
--save openedFile as JPEG with compression level low in Path_to_Converted_File (low|medium|high)
close openedFile
end tell
end repeat
end open
將圖像事件和sips
混合起來比有用更令人困惑,而且由於sips
可以執行您正在尋找的各種選項(例如 3 和 4),因此將它用於所有事情更有意義。 為各種選項設置一些變量將使您可以根據需要更改它們,或者添加首選項等。 sips
手冊頁將為您提供有關各種選項的更多詳細信息; 我為以下腳本中使用的注釋添加了注釋:
on run
open (choose file with prompt "Select image files to turn into JPEGs:" with multiple selections allowed)
end run
on open draggeditems
set destination to (((path to desktop folder) as text) & "End:") -- folder path (trailing delimiter)
set format to "jpeg" -- jpeg | tiff | png | gif | jp2 | pict | bmp | qtif | psd | sgi | tga
set extension to ".jpg" -- extension to match format
set compression to 10 -- low | normal | high | best | <percent>
set profile to quoted form of "/System/Library/ColorSync/Profiles/AdobeRGB1998.icc" -- POSIX path to color profile
repeat with thisFile in draggeditems
set theName to justTheName for thisFile
set originalFile to quoted form of POSIX path of thisFile
set convertedFile to quoted form of POSIX path of (destination & theName & extension)
do shell script "sips -s format " & format & " -s formatOptions " & compression & " -m " & profile & space & originalFile & " --out " & convertedFile
end repeat
end open
on justTheName for filePath
tell application "System Events" to tell disk item (filePath as text)
set {fileName, extension} to {name, name extension}
end tell
if extension is not "" then set fileName to text 1 thru -((count extension) + 2) of fileName -- just the name part
return fileName
end justTheName
編輯添加: shell 腳本需要 POSIX 路徑,因此傳遞給open
處理程序的別名在它們包含空格的情況下被強制和引用。
你的劇本有很多錯誤。 目前尚不清楚為什么要在將文件發送到 shell 命令之前打開文件進行寫入。 sips 不對打開的 FILE 引用進行操作。 sips 需要從 POSIX 路徑打開文件。 我認為這可能會做你想要的(你需要實現錯誤檢查等):
on open draggeditems
set End_Folder to "~/Desktop/End/"
repeat with currentFile in draggeditems
do shell script "sips --setProperty formatOptions 10 " & quoted form of POSIX path of currentFile & " --out " & End_Folder
end repeat
end open
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.