Bug - "Kind as text" is broken in Applescript Standalone
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.
In hindsite I suppose it would be cleaner to do the conversion to string right in the converter. Property value in, string out.
Untested:
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.
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:
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
0
-
Case number 258288
The Applescript below below is now tested and it works.[quote="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: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 convertKind0
Post is closed for comments.
Comments
1 comment