我有一台尼康相机,可以输出很好的 NEF 原始文件,而不是很好的 JPEG 文件。我可以使用 Mac OSX 10.6.8 (Snow Leopard) 附带的 Preview 应用程序来简单地打开 NEF 和 SaveAs JPEG 以创建一个大小约为 1/6 的文件,该文件与原始 NEF 几乎无法区分。
[编辑] 这是按需要工作的最终脚本,带有注释和一些错误测试:
(*
AppleScript to convert Nikon raw NEF files into much smaller JPG files.
The JPG files will inherit the file date and time of the source NEF files.
Note that any JPG files in the target folder that have the same name
as a NEF file in that folder, will be overwritten.
*)
-- User selects target folder with NEF files to convert and save there.
set theImageFolder to choose folder with prompt "
Select a folder containing fileⁿ.NEF images to
convert into JPEG images and SaveAs: fileⁿ.JPG"
set theOutputFolder to theImageFolder
-- Finder locates NEF files, ignoring other file types in the target folder.
tell application "Finder"
set theImages to every file of theImageFolder whose name extension is "NEF"
end tell
-- Image Events app processes the images.
tell application "Image Events"
launch
repeat with a from 1 to length of theImages
-- Get file name as text string.
set theImage to file ((item a of theImages) as string)
-- Get date/time of source NEF file.
tell application "Finder" to set fileTimestamp to creation date of theImage
set theImageReference to open theImage
tell theImageReference
set theImageName to name
-- Detect the .NEF extension to replace with .JPG on output.
set savedDelimiters to AppleScript's text item delimiters
-- Split filename string into list, using "." as a delimiter.
set AppleScript's text item delimiters to {"."}
set delimitedList to every text item of theImageName
-- Remove the .NEF extension from the list, if it was there.
ignoring case
--Process only NEF files.
if last item of delimitedList is "NEF" then
set filenameList to items 1 thru -2 of delimitedList
set theImageName to filenameList as string
end if
end ignoring
-- Restore delimiters to default in case it had previously been changed.
set AppleScript's text item delimiters to savedDelimiters
-- Construct full path of file to save, with JPG as output file extension.
set saveImageName to ((theOutputFolder as string) & theImageName & ".JPG")
-- Check if a file with the output JPG file name is already present in the target folder.
tell application "Finder"
if exists file saveImageName then
-- Abort script if user doesn't want to overwrite this file and continue.
beep
if button returned of (display dialog " An identical JPG file is already at:
" & saveImageName & "
Would you like to:" buttons {"Replace it and continue", "Abort"} default button "Abort") is "Abort" then exit repeat
end if
end tell
-- SaveAs the file in JPEG format, leaving the source NEF file unmodified.
set saveImageName to save in saveImageName as JPEG
--Match the output JPG file date/time to that of the NEF source file.
tell application "Finder" to set modification date of saveImageName to fileTimestamp
end tell
end repeat
end tell
tell application "Finder"
display alert "Done. Duplicated selected NEF files in
" & theOutputFolder & "
as JPGs with dates/times matching NEFs."
end tell
下面是我最初尝试创建 AppleScript 以节省我在数百个 NEF 文件上使用 Preview 应用程序手动执行此操作所需的时间。它有效,但是这个网站上乐于助人的人帮助我大大改进了它。正如您从初始用户提示中看到的那样,我只想在现有 JPG 文件将被替换的情况下提示用户。我还希望将输出文件名设为n .JPG 而不是n .NEF.jpg 并让输出 JPG 文件继承原始 NEF 文件的创建日期和时间。我欢迎任何建议,但由于我已经走到这一步,我的偏好是避免添加 shell 脚本,如果可能的话,使用 AppleScript 来完成。
set theImageFolder to choose folder with prompt "Note: This script will replace any existing files in the selected folder matching
the name of a NEF file and end in a JPG extension with a new file of that name.
For example, X.NEF will create X.JPG and replace any existing file named X.JPG
that was already in the selected folder (not in any other folders). To begin now,
Select a folder with NEF images to convert into JPEG images:"
set theOutputFolder to theImageFolder
tell application "Finder"
set theImages to every file of theImageFolder whose name extension is "NEF"
end tell
tell application "Image Events"
launch
repeat with a from 1 to length of theImages
set theImage to file ((item a of theImages) as string)
set theImageReference to open theImage
tell theImageReference
set theImageName to name
save in ((theOutputFolder as string) & theImageName & ".JPG") as JPEG
end tell
end repeat
end tell
tell application "Finder"
display alert "Done. All NEF files in the selected folder have been duplicated in JPEG format."
end tell