Importing images and the import settings class

Discussion regarding all scripting related questions
Please DO NOT post to this thread anything that is not directly related to scripting of Capture One.

Importing images and the import settings class

Postby iKenndac » Thu Nov 01, 2018 3:32 pm

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:

Code: Select all
tell application "Capture One 11"
   set doc to first document
   set settings to import settings of doc
end tell


The output is:

Code: Select all
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:

Code: Select all
 set destType to destination type of settings


…the script fails:

Code: Select all
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!

Code: Select all
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:

Code: Select all
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!
iKenndac
 
Posts: 2
Joined: Tue Dec 15, 2015 10:32 pm

Re: Importing images and the import settings class

Postby Eric Nepean » Sun Nov 04, 2018 3:13 pm

Here's working code for your application; you can't use the "settings" variable as an intermediate

Code: Select all
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
Code: Select all
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 tell
Cheers, Eric
[late 2015 iMac, 4GHz i7, 24GB RAM, external SSDs. GX8, E-M1, GX7, GM5, GM1 ....]
Eric Nepean
 
Posts: 266
Joined: Sat Oct 25, 2014 8:02 am

Re: Importing images and the import settings class

Postby iKenndac » Thu Nov 08, 2018 3:40 pm

Hi Eric,

Thank you very much for your help! I really appreciate it :D
iKenndac
 
Posts: 2
Joined: Tue Dec 15, 2015 10:32 pm


Return to Scripting



Who is online

Users browsing this forum: No registered users and 1 guest