Importing images and the import settings class
Hello,
I'm working on an application that copies images from WiFi-enabled cameras to your Mac. Currently, we support Photos, Lightroom, etc, and are working on adding support for Capture One (via Apple Events).
To start, we're using AppleScript to build a proof-of concept. I can get images imported no problem, but I'm having a lot of trouble with import settings.
First, I'd like to be able to tell if the user's import settings are set to "Inside Catalog" or "Custom Folder". I wrote a script like this:
The output is:
…so far, so good!
However, if I add the following line:
…the script fails:
Well, maybe I can set the settings!
This fails on the "set destination type…" line with:
How do we interact with Capture One's import settings via AppleScript? Ultimately, we'd like to have our app to be smart - if the import settings are "Current Location" we'll let the user choose a folder and a subfolder organisation scheme, otherwise we'll copy the images to a temp directory and allow Capture One to place the images where they should go. For this to work, we need to be able to work with the import settings via scripting.
Thank you!
I'm working on an application that copies images from WiFi-enabled cameras to your Mac. Currently, we support Photos, Lightroom, etc, and are working on adding support for Capture One (via Apple Events).
To start, we're using AppleScript to build a proof-of concept. I can get images imported no problem, but I'm having a lot of trouble with import settings.
First, I'd like to be able to tell if the user's import settings are set to "Inside Catalog" or "Custom Folder". I wrote a script like this:
tell application "Capture One 11"
set doc to first document
set settings to import settings of doc
end tell
The output is:
import settings id "ImportSettingsAppleScript-CO-83427-8" of document "Capture One Catalog" of application "Capture One 11"…so far, so good!
However, if I add the following line:
set destType to destination type of settings…the script fails:
error "Capture One 11 got an error: Invalid key form." number -10002 from import settings id "ImportSettingsAppleScript-CO-83427-9" of document "Capture One Catalog"Well, maybe I can set the settings!
tell application "Capture One 11"
set doc to first document
tell doc
set settings to import options
set destination type of settings to custom
set destination folder of settings to "/Users/dkennett/Downloads/Capture One Import"
set import settings to settings
import source "/Users/dkennett/Downloads/Capture One Export"
end tell
end tell
This fails on the "set destination type…" line with:
error "Can’t set «class Cidt» of «class CimO» to «constant CideCicu»." number -10006 from «class Cidt» of «class CimO»How do we interact with Capture One's import settings via AppleScript? Ultimately, we'd like to have our app to be smart - if the import settings are "Current Location" we'll let the user choose a folder and a subfolder organisation scheme, otherwise we'll copy the images to a temp directory and allow Capture One to place the images where they should go. For this to work, we need to be able to work with the import settings via scripting.
Thank you!
0
-
Here's working code for your application; you can't use the "settings" variable as an intermediate
use AppleScript version "2.4" -- always use this in the first line (specify 2.4 or 2.5)
use scripting additions -- always use this in the first line to handle an obscure Applescript bug
set debug_notify to true
set debug_log to false
set restore_CL to true
set download_file_path_a to (get path to downloads folder)
set import_folder__name to "Capture One Import"
set import_folder__path to get POSIX path of (get download_file_path_a as string) & import_folder__name
if debug_log then log "Import Folder "" & import_folder__path & """
if debug_notify then display notification "Import Folder "" & import_folder__path & """
tell application "Capture One 11"
set theDoc to first document
set theDestinationType to (destination type of import settings of theDoc) as text
set destination type of import settings of theDoc to custom
set destination folder of import settings of theDoc to import_folder__path
## Can't just use "current location" since this will fail if the localisation is not english
if restore_CL or ("current location" = (get current location as text)) then set destination type of import settings of theDoc to current location
end tell
Edit- Fixed a problem in the last line
- Handles the case when user has both catalogs and sessionsopen
- improved the tell structure
use AppleScript version "2.4"
use scripting additions
set debug_notify to true
set debug_log to true
set restore_CL to false
set download_file_path_a to (get path to downloads folder)
set import_folder__name to "Capture One Import"
set import_folder__path to get POSIX path of (get download_file_path_a as string) & import_folder__name
if debug_log then log "Import Folder "" & import_folder__path & """
if debug_notify then display notification "Import Folder "" & import_folder__path & """
tell application "Capture One 11"
set theDocs to (get every document whose kind is catalog)
if 0 = (count of theDocs) then error "There are no catalogs open"
## Do something if there is more than one catalog open?
tell (get first item of theDocs) to tell its import settings
set theDestinationType to destination type as text
set destination type to custom
set destination folder to import_folder__path
if debug_log then
set theProperties to (get properties) -- do not combine with the next line or you will get the properties of the script
tell me to log {"Properties of "Import Settings": ", theProperties}
end if
## Example - shouldn't use "current location" for logical tests because this will fail if the localisation is not English
if restore_CL or (theDestinationType = (get current location as text)) then set destination type to current location
end tell
end tell0 -
Hi Eric,
Thank you very much for your help! I really appreciate it 😄0
投稿コメントは受け付けていません。
コメント
2件のコメント