Email the Selection
CO lacks a native way to email selected variants. This script works well enough for me in CO20. Adaptation for CO21 unknown in view of changes to the way the latter handles exporting, but could be as simple as changing references to "Capture One 20" to "Capture One 21"?
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
property emailRecipeName : "JPEG - Email Script"
-- Initiate an email with selected variants as attachments. No warranty or guarantees.
-- The script processes variants by way of recipe 'JPEG - Email Script', which it creates
-- on first run. Edit this recipe manually thereafter to make any required changes.
-- But note that the script always prompts for the primary dimension.
-- The script exports processed variants to the user's temporary folder first
-- then attaches these files to a new Mail message. The exported files are then deleted.
set dialogTitle to "Email Images"
set outputFiles to {}
set appIcon to alias (((path to applications folder) as text) & "Capture One 20.app:Contents:Resources:AppIcon.icns")
set rootFolderLocation to path to temporary items folder as text
tell application "Capture One 20"
set vv to (get selected variants)
set currentDocument to current document
if vv is {} then
try
display dialog "No variants selected!" buttons {"Cancel"} default button "Cancel" with icon stop with title dialogTitle
on error errMsg number errNum
if errNum is -128 then return
end try
end if
tell currentDocument
try
set emailRecipe to recipe emailRecipeName
-- does the temporary items folder change from time to time? In case it does:
set emailRecipe's root folder location to file rootFolderLocation
on error
-- Create the recipe first time round using settings from shipping JPEG recipe.
-- Any changes can be made in the UI to tweak these later.
set emailRecipe to make new recipe with properties {bits:8, color profile:"sRGB Color Space Profile", export crop method:respect, ignore crop:false, include annotations:false, include Camera Metadata:false, include copyright:true, include GPS:false, include Other Metadata:false, include overlay:false, include ratings:false, JPEG quality:80, name:emailRecipeName, output format:JPEG, output sub folder:"", root folder location:file rootFolderLocation, root folder type:custom location, scaling method:Long_Edge, sharpening:for screen, sharpening amount:60.0, sharpening distance:100.0, sharpening distance type:percent of diagonal, sharpening radius:0.600000023842, sharpening threshold:0.0, thumbnails:false}
-- Some properties must be set after others: e.g. scaling unit after scaling method
tell emailRecipe to set {its enabled, its root folder type, its scaling unit, its primary scaling value} to {false, custom location, pixels, 500}
(* Beware Width and Height enumerators for scaling method above if you change it
from Long_Edge. CO AS bug. They are replaced as 'width' and 'height'.
See https://macscripter.net/viewtopic.php?id=47763
If you want Width, then, assuming we're using Script Debugger, not Apple's Script Editor, you need to:
1. Write any other value but Width. Suggest Fixed.
2. Switch Script Debugger to Raw (Chevron) Syntax, under View menu.
3. Edit «constant CRstRsfx» to read «constant CRstRswd»
4. Recompile and save
5. Any fruther editing destroys the change and reinstates 'width' or 'height'.
A script for Script Debugger helps with this repetitive procedure. Done.
*)
end try
-- Get recipe's stored scaling value for prompt
tell emailRecipe
set scalingValue to its primary scaling value
end tell
end tell
end tell
set variantNames to {}
repeat with v in vv
copy name of v to end of variantNames
end repeat
set variantNameSummary to my summariseString(variantNames, 3)
-- Any change to this value is stored in the recipe for later iterations.
display dialog "Long edge (px) for " & variantNameSummary default answer scalingValue buttons {"Cancel", "OK"} default button "OK" with title dialogTitle with icon appIcon
set scalingResult to text returned of result
-- Needs some bounds/error checking... WIP
-- Get the output folder for the recipe: custom or standard Output Location for current document
tell application "Capture One 20"
-- either Custom
if root folder type of emailRecipe is custom location then
set rfl to POSIX path of (get root folder location of emailRecipe) --as text
else
-- or standard Output Location
tell currentDocument to set rflAlias to its output
set rfl to POSIX path of rflAlias
end if
-- append any sub folder nominated. Not applicable with temporary items folder?
if emailRecipe's output sub folder is not "" then
set rfl to rfl & emailRecipe's output sub folder & "/"
end if
tell currentDocument
set emailRecipe's primary scaling value to scalingResult
end tell
-- Make output files in temporary folder, set within recipe as named in emailRecipeName property.
-- Then list them for Mail to attach
repeat with v in vv
set outputFileName to rfl & v's name & ".jpg"
-- development: file may be left hanging during debug; delete if so.
tell application "System Events"
if exists file outputFileName then
delete file outputFileName
end if
end tell
try
set outputResult to process v recipe emailRecipeName
on error errMsg number errNum
if errNum is -43 then -- invalid output location
set emailRecipe's root folder location to file rootFolderLocation
-- try again
set outputResult to process v recipe emailRecipeName
else
display dialog "Error " & errNum & ": " & errMsg buttons {"Cancel", "OK"} default button "OK" with title "Email Images Script" with icon caution
end if
end try
copy outputFileName to end of outputFiles
end repeat
end tell
tell application "System Events"
repeat with f in outputFiles
repeat while not (exists file f)
delay 0.2
end repeat
end repeat
end tell
tell application "Mail"
set newMessage to make new outgoing message
repeat with f in outputFiles
tell newMessage
try
make new attachment at end of attachments with properties {file name:f}
on error errMsg number errNum
display dialog "Error " & errNum & ": " & errMsg buttons {"Cancel", "OK"} default button "OK"
end try
end tell
tell application "System Events"
try
delete file f
on error
display dialog "Some temporary files not deleted" buttons {"OK"} default button "OK" giving up after 1
end try
end tell
end repeat
activate
end tell
-- make a shortened description of a list of items: "... and x others"
to summariseString(inList, nQuoted)
set remainderCount to (count of inList) - nQuoted
if remainderCount > 0 and nQuoted > 0 then
set lastItem to (((count of inList) - nQuoted) as text) & " other"
if remainderCount > 1 then set lastItem to lastItem & "s"
set summList to items 1 thru nQuoted of inList & lastItem
else if nQuoted < 1 then
set summList to {((count of inList) as text) & " items"}
else
set summList to inList
end if
if (count of summList) > 1 then
set endString to item -2 of summList & " and " & item -1 of summList
else if (count of summList) is 1 then
set endString to item 1 of summList
else
set endString to ""
end if
if (count of summList) > 2 then
set workList to items 1 thru -3 of summList & endString
set saveTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {", "}
set endString to workList as text
set AppleScript's text item delimiters to saveTID
end if
return endString
end summariseString
(*
-- Simple version; no recipe; variants not processed with adjustments
set photoPaths to {}
tell application "Capture One 20"
set vv to (get selected variants)
repeat with v in vv
set pip to v's parent image's path
copy pip to end of photoPaths
end repeat
end tell
tell application "Mail"
set newMessage to make new outgoing message
tell newMessage
repeat with p in photoPaths
log p
try
make new attachment with properties {file name:p}
end try
end repeat
end tell
activate
end tell
*)
0
Post ist für Kommentare geschlossen.
Kommentare
0 Kommentare