Created
January 9, 2025 14:40
-
-
Save jkrumbiegel/33a489dcacab2da91ba3761c1a30cf2d to your computer and use it in GitHub Desktop.
Capture One move to date-annotated folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use AppleScript version "2.4" -- Yosemite (10.10) or later | |
use framework "Foundation" | |
use scripting additions | |
tell application "Capture One" | |
tell current document | |
set _variants to every variant whose selected is true | |
-- Initialize variables to store the first and last date | |
set startDate to missing value | |
set endDate to missing value | |
repeat with _variant in _variants | |
set _date to EXIF capture date of parent image of _variant | |
-- Update startDate and endDate based on _date | |
if startDate is missing value or _date < startDate then | |
set startDate to _date | |
end if | |
if endDate is missing value or _date > endDate then | |
set endDate to _date | |
end if | |
end repeat | |
end tell | |
end tell | |
set dateFormatter to current application's NSDateFormatter's new() | |
dateFormatter's setDateFormat:"yyyy-MM-dd" | |
set startDateString to (dateFormatter's stringFromDate:startDate) as string | |
set endDateString to (dateFormatter's stringFromDate:endDate) as string | |
if startDateString = endDateString then | |
set dateRange to startDateString | |
else | |
set dateRange to (startDateString) & "-" & (endDateString) | |
end if | |
set folderName to text returned of (display dialog "Enter the name for the folder to be created:" default answer dateRange & " ") | |
set picturesPath to (path to pictures folder as text) | |
set folderPath to picturesPath & folderName | |
tell application "Finder" | |
if not (exists folder folderPath) then | |
set _folder to make new folder at picturesPath with properties {name:folderName} | |
else | |
error "Folder \"" & folderName & "\" already exists in the Pictures directory." | |
end if | |
end tell | |
tell application "Capture One" | |
tell current document | |
set _impaths to {} | |
repeat with _variant in _variants | |
set _image to get parent image of _variant | |
set _imname to name of _image | |
set _impath to path of _image | |
set _imfile to file of _image | |
if _impath is not in _impaths then | |
set end of _impaths to _impath | |
tell application "Finder" | |
set _imfile_moved to move _imfile to _folder | |
end tell | |
relink _image to path POSIX path of (_imfile_moved as text) | |
end if | |
end repeat | |
end tell | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment