Bug - "Kind as text" is broken in Applescript Standalone

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

Bug - "Kind as text" is broken in Applescript Standalone

Postby Eric Nepean » Sun Jul 30, 2017 8:34 am

When an Applescript runs under Script Editor, there is no problem in executing something this: get kind of current document as text or this get kind of some_collection as text
For a document you will get either "catalog" or "session", for a collection you will get "project" or "album" or a few other possibilities.

However, if you make your Applescript a bundle or an application, and try to execute it through the Capture One Script menu, this is broken.

Instead of "catalog", you get "<constant ****COct>"
Instead of "project", you get "<constant ****COpj>"
... and so forth

Effectively, the script is getting the name of the enum instead of the value.

I will shortly open a ticket to ask that CO fix the bug.

Meanwhile, here is a bit of code to get around it.
After you tell application "Capture One 10" to get kind of some_document as string , you send the resulting string to this converter.
If the string is correct (i.e. doesn't contain the character string "constant") it returns the same string - that handles the case when the script is being run by Script Editor.
Otherwise it matches the last two letters to the string that should have been sent, and returns that. It works for kind from collections and from documents.

Code: Select all
on convertKind(kind_s)
   if kind_s does not contain "constant" then
      return kind_s
   else
      set code_start to (get length of kind_s) - 2
      set kind_code to get (text code_start thru (code_start + 1) of kind_s)
      
      if kind_code = "pj" then
         set kind_res to "project"
      else if kind_code = "gp" then
         set kind_res to "group"
      else if kind_code = "al" then
         set kind_res to "album"
      else if kind_code = "sm" then
         set kind_res to "smart album"
      else if kind_code = "fv" then
         set kind_res to "favorite"
      else if kind_code = "ff" then
         set kind_res to "folder"
      else if kind_code = "ct" then
         set kind_res to "catalog"
      else if kind_code = "sd" then
         set kind_res to "session"
      else
         error "Kind code not found: " & kind_s
      end if
   end if
   return kind_res
end convertKind

In hindsite I suppose it would be cleaner to do the conversion to string right in the converter. Property value in, string out.

Untested:
Code: Select all
on convertKind(kind_property)
   tell application "Capture One 10" to set kind_s to kind_property as text
   if kind_s does not contain "constant" then
      return kind_s
   else
      set code_start to (get length of kind_s) - 2
      set kind_code to get (text code_start thru (code_start + 1) of kind_s)
      
      if kind_code = "pj" then
         set kind_res to "project"
      else if kind_code = "gp" then
         set kind_res to "group"
      else if kind_code = "al" then
         set kind_res to "album"
      else if kind_code = "sm" then
         set kind_res to "smart album"
      else if kind_code = "fv" then
         set kind_res to "favorite"
      else if kind_code = "ff" then
         set kind_res to "folder"
      else if kind_code = "ct" then
         set kind_res to "catalog"
      else if kind_code = "sd" then
         set kind_res to "session"
      else
         error "Kind code not found: " & kind_s
      end if
   end if
   return kind_res
end convertKind
Cheers
Eric
(OSX 10.12, iMac and MacBook Air, Panasonic GX7,GM5,G5, Olympus E-M1)
Eric Nepean
 
Posts: 385
Joined: Sat Jun 28, 2014 8:54 pm
Location: Ontario, Canada

Re: Bug - "Kind as text" is broken in Applescript Standalone

Postby Eric Nepean » Wed Aug 02, 2017 1:45 am

Case number 258288

The Applescript below below is now tested and it works.

Eric Nepean wrote:... I suppose it would be cleaner to do the conversion to string right in the converter. Property value in, string out.
Untested:
Code: Select all
on convertKind(kind_property)
   tell application "Capture One 10" to set kind_s to kind_property as text
   if kind_s does not contain "constant" then
      return kind_s
   else
      set code_start to (get length of kind_s) - 2
      set kind_code to get (text code_start thru (code_start + 1) of kind_s)
      
      if kind_code = "pj" then
         set kind_res to "project"
      else if kind_code = "gp" then
         set kind_res to "group"
      else if kind_code = "al" then
         set kind_res to "album"
      else if kind_code = "sm" then
         set kind_res to "smart album"
      else if kind_code = "fv" then
         set kind_res to "favorite"
      else if kind_code = "ff" then
         set kind_res to "folder"
      else if kind_code = "ct" then
         set kind_res to "catalog"
      else if kind_code = "sd" then
         set kind_res to "session"
      else
         error "Kind code not found: " & kind_s
      end if
   end if
   return kind_res
end convertKind
Cheers
Eric
(OSX 10.12, iMac and MacBook Air, Panasonic GX7,GM5,G5, Olympus E-M1)
Eric Nepean
 
Posts: 385
Joined: Sat Jun 28, 2014 8:54 pm
Location: Ontario, Canada


Return to Scripting



Who is online

Users browsing this forum: No registered users and 1 guest