Capture One Crashes While AppleScript Runs

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

Capture One Crashes While AppleScript Runs

Postby SeanMurp » Tue Jul 25, 2017 9:50 pm

Hey all,
We're using an AppleScript to create a new session (with a name input by the user), set preferences, select custom keyboard shortcut file, select custom workspace and input a custom recipe. We are seeing an issue with this one script where Capture One crashes midway through the running of the script the first time it is run. Upon running it a second time it works successfully.

There isn't one place where the script crashes but I have seen it crash the most during the recipe creation. Even after removing that section of code we see the same issue. And, after a successful completion of the script it then reverts back to an unsuccessful running. Run it again and it will succeed again. Our shooting bays will use this about four times per day (times 15 shooting bays) and it slows down our work.

Are there any things currently encouraging Capture One to crash with AppleScripts and creating sessions?

Unsure what might be useful I'm pasting in the section of code that I most frequently see the script crash on.

Code: Select all
tell application "Capture One 10"
      -- disable all other default recipes.  Custom recipes will not be turned off automatically.
      if (exists recipe "A3 300dpi Print ready" of current document) then set enabled of recipe "A3 300dpi Print ready" of current document to false
      if (exists recipe "JPEG sRGB 1600px for web" of current document) then set enabled of recipe "JPEG sRGB 1600px for web" of current document to false
      if (exists recipe "JPEG sRGB QuickProof (preview size)" of current document) then set enabled of recipe "JPEG sRGB QuickProof (preview size)" of current document to false
      if (exists recipe "JPEG sRGB" of current document) then set enabled of recipe "JPEG sRGB" of current document to false
      if (exists recipe "TIFF Adobe RGB (1998) (8bit)" of current document) then set enabled of recipe "TIFF Adobe RGB (1998) (8bit)" of current document to false
      
      --Create new recipe if it does not exist
      if not (exists recipe "SHOPBOP JPEG 100% (sRGB)" of current document) then make new recipe of current document with properties {name:"SHOPBOP JPEG 100% (sRGB)"}
      --Basic tab
      set enabled of recipe "SHOPBOP JPEG 100% (sRGB)" of current document to true
      set output format of recipe "SHOPBOP JPEG 100% (sRGB)" of current document to JPEG
      set JPEG quality of recipe "SHOPBOP JPEG 100% (sRGB)" of current document to 100
      set color profile of recipe "SHOPBOP JPEG 100% (sRGB)" of current document to "sRGB Color Space Profile"
      set pixels per inch of recipe "SHOPBOP JPEG 100% (sRGB)" of current document to 72
      set scaling method of recipe "SHOPBOP JPEG 100% (sRGB)" of current document to Fixed
      set scaling unit of recipe "SHOPBOP JPEG 100% (sRGB)" of current document to Pixels
      --set application see manual set section below
      
      --File tab
      --set root folder type  see manual set section below
      set output sub name of recipe "SHOPBOP JPEG 100% (sRGB)" of current document to ""
      set output sub folder of recipe "SHOPBOP JPEG 100% (sRGB)" of current document to ""
      set thumbnails of recipe "SHOPBOP JPEG 100% (sRGB)" of current document to true
      
      --Adjustments tab
      --set sharpened of recipe "SHOPBOP JPEG 100% (sRGB)" of document 1 to true --there are four options to choose from.  True and false err
      set ignore crop of recipe "SHOPBOP JPEG 100% (sRGB)" of current document to true
      
      --Metadata tab
      set include ratings of recipe "SHOPBOP JPEG 100% (sRGB)" of current document to true
      set include copyright of recipe "SHOPBOP JPEG 100% (sRGB)" of current document to false
      set include GPS of recipe "SHOPBOP JPEG 100% (sRGB)" of current document to false
      set include Camera Metadata of recipe "SHOPBOP JPEG 100% (sRGB)" of current document to true
      set include Other Metadata of recipe "SHOPBOP JPEG 100% (sRGB)" of current document to true
      
      --Watermark tab
      --doesn't work
      --set kind of watermark of recipe "SHOPBOP JPEG 100% (sRGB)" of current document to none
      
      --Output Location section
      --set output of current document to outputFolder as alias
      --set output sub path of document 1 to ""
      
      
      --Output Naming section
      set output name format of current document to "Image Name"
      set output name of current document to "Job name"
      
      --Metadata Copy From Last
      --set capture metadata of next capture settings of current document to copy from last
      
      --Reset Batch Renaming Counter to zero
      set counter of batch rename settings of current document to 1
   end tell
SeanMurp
 
Posts: 71
Joined: Wed Nov 02, 2016 4:30 am

Re: Capture One Crashes While AppleScript Runs

Postby Eric Nepean » Wed Jul 26, 2017 7:26 am

I would try replacing the refrence to "current doc" with an an absolute reference like document 1. "Current document" can change while the script is running.

Perhaps a bit of code like this:
Code: Select all
## This line of code would take care of it, but does not work: (suspect a bug in COP)
## set current_doc_abs to (get  document whose name is current_doc_name)  - inside a tell application "Capture One 10" section

## Therefore a less elegant approach is needed
tell application "Capture One 10"
   set current_doc_name to (get name of current document) as string
   set current_doc_kind to (get kind of current document) as string
   if current_doc_kind ≠ "catalog" then error -- if you are using sessions, then change this accordingly
   set doc_list to get documents
   set found_doc to false
   repeat with this_doc in doc_list
      try
         set this_doc_name to (get name of this_doc) as string
         set this_doc_kind to (get kind of this_doc) as string
         if (this_doc_name = current_doc_name) and (this_doc_kind = current_doc_kind) then
            set current_doc_abs to this_doc
            set found_doc to true
            exit repeat
         end if
      end try
   end repeat
   if not found_doc then error "Document not found"
end tell
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: Capture One Crashes While AppleScript Runs

Postby Eric Nepean » Wed Jul 26, 2017 8:07 am

Here is a much better piece of code.

If you check the Script Editor log window under "events" or "replies" you should be able to see the last Apple event and the last reply before COP crashes. This will be very useful information.

Code: Select all
tell application "Capture One 10"
   set {current_doc_name, current_doc_kind} to (get {name, kind} of current document)
   set current_doc_abs_list to (get every document whose name is current_doc_name and kind is current_doc_kind)
   
   ##-- if you are using sessions, then change this next line accordingly
   set current_doc_kind to current_doc_kind as string
   
   set number_of_hits to count of current_doc_abs_list
   if number_of_hits = 0 then
      error "Could not find find " & current_doc_kind & current_doc_name
   else if number_of_hits > 1 then
      error "Found more than one " & current_doc_kind & " with the name " & current_doc_name
   else
      set current_doc_abs to item 1 of current_doc_abs_list
   end if
end tell
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: Capture One Crashes While AppleScript Runs

Postby SeanMurp » Thu Jul 27, 2017 3:05 pm

Thanks a lot for the code Eric. The current document addition to the Capture One dictionary was a welcome addition in 10.1 (the prior alternative gave us lots of issues), but I'll give your code a try.
SeanMurp
 
Posts: 71
Joined: Wed Nov 02, 2016 4:30 am

Re: Capture One Crashes While AppleScript Runs

Postby SeanMurp » Thu Jul 27, 2017 4:27 pm

Well, I gave it a go and was very hopeful after the first running of the script. Unfortunately subsequent runs of the script results in the same crash/success pattern as I was experiencing earlier. The last few crashes being on this same line of the recipe creation:

Code: Select all
set output format of recipe "SHOPBOP JPEG 100% (sRGB)" of current_doc_abs to JPEG


Links to full code below:
https://s3.amazonaws.com/externalsendfiles/Setup_Session_IP_v1.0.0_TESTING_To_Prevent_Crash.app -- this one contains Eric's suggested edits
https://s3.amazonaws.com/externalsendfiles/Setup_Session_IP_v1.0.0_Working_Drive.app -- original version with 'current document' references
SeanMurp
 
Posts: 71
Joined: Wed Nov 02, 2016 4:30 am

Re: Capture One Crashes While AppleScript Runs

Postby Eric Nepean » Thu Jul 27, 2017 4:39 pm

SeanMurp wrote:Thanks a lot for the code Eric. The current document addition to the Capture One dictionary was a welcome addition in 10.1 (the prior alternative gave us lots of issues), but I'll give your code a try.

I'm kind of shooting in the dark, since I don't know how your Applescript crashes, I would know more if I saw the Apple Events before the crash. But current document is a recent COP change, and so there is an elevated chance this is the cause.

I do use current document and current collection and find them useful, but carefully, since in each case the object they reference may change while the Applescript is running.

In my code snippet I quickly convert that current document reference to a something I call an absolute reference - absolute meaning that it is a reference that always points to the same document. Using an absolute reference makes the Applescript unaffected by changes in current document while it runs.

current document references the document that receives the focus and the mouseclicks and keyclicks from COP and is its frontmost document. This may change at anytime COP decides that another document becomes the current document. The Applescript will not be notified that a change has occurred.

In an Applescript with a few short commands, that is no problem as current document is unlikely to change while it runs. In a longer Applescript, it becomes a vulnerability as something like a user mouse click or some other internal COP process may cause current document to change while the script is running ... referring to a different documents with completely different contents - and then things will quickly go sideways.
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: Capture One Crashes While AppleScript Runs

Postby Eric Nepean » Thu Jul 27, 2017 4:41 pm

SeanMurp wrote:Well, I gave it a go and was very hopeful after the first running of the script. Unfortunately subsequent runs of the script results in the same crash/success pattern as I was experiencing earlier. The last few crashes being on this same line of the recipe creation:

Code: Select all
set output format of recipe "SHOPBOP JPEG 100% (sRGB)" of current_doc_abs to JPEG


Links to full code below:
https://s3.amazonaws.com/externalsendfiles/Setup_Session_IP_v1.0.0_TESTING_To_Prevent_Crash.app -- this one contains Eric's suggested edits
https://s3.amazonaws.com/externalsendfiles/Setup_Session_IP_v1.0.0_Working_Drive.app -- original version with 'current document' references


Can we also get a listing of the Apple events or replies just before this happens?
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: Capture One Crashes While AppleScript Runs

Postby Eric Nepean » Thu Jul 27, 2017 4:45 pm

SeanMurp wrote:Well, I gave it a go and was very hopeful after the first running of the script. Unfortunately subsequent runs of the script results in the same crash/success pattern as I was experiencing earlier. The last few crashes being on this same line of the recipe creation:

Code: Select all
set output format of recipe "SHOPBOP JPEG 100% (sRGB)" of current_doc_abs to JPEG


Links to full code below:
https://s3.amazonaws.com/externalsendfiles/Setup_Session_IP_v1.0.0_TESTING_To_Prevent_Crash.app -- this one contains Eric's suggested edits
https://s3.amazonaws.com/externalsendfiles/Setup_Session_IP_v1.0.0_Working_Drive.app -- original version with 'current document' references


I can't access the links. I get AccessDenied:
Access DeniedAD3FD05116C0F71EvepB+1yPkAwNsHP2jNU8Phl52+yu4r8aaJCQVuQTWk8Bzmo5ft6IVuzVU8m2b703mjlEXN1Yefo=
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: Capture One Crashes While AppleScript Runs

Postby SeanMurp » Thu Jul 27, 2017 5:28 pm

Sorry, that access denied must be since those are apps and therefore a folder structure essentially. Here is a zip with both. https://externalsendfiles.s3.amazonaws.com/IP_Setup_Sessions.zip

Just figured out how to see Apple Events. :-) Here is everything from the error, unfortunately, doesn't say a lot:

tell current application
do shell script "/bin/ls /Volumes"
system info
system info
end tell
tell application "System Events"
get value of property list item "DT_Setup_Session" of property list item "currentVersionNumbers" of property list file "/Volumes/extensis/IP_Resources/_DT_Workflow_Applications/pLists_DO_NOT_DELETE/userApp_Version_Check.plist"
exists property list item "seanmurp" of property list item "DT_Setup_Session" of property list item "IP" of property list file "/Volumes/extensis/IP_Resources/_DT_Workflow_Applications/pLists_DO_NOT_DELETE/userApp_Version_Check.plist"
get value of property list item "seanmurp" of property list item "DT_Setup_Session" of property list item "IP" of property list file "/Volumes/extensis/IP_Resources/_DT_Workflow_Applications/pLists_DO_NOT_DELETE/userApp_Version_Check.plist"
end tell
tell current application
do shell script "date +'%Y-%m-%d_%H-%M-%S'"
end tell
tell application "System Events"
exists folder "/Volumes/WORKING/Sessions/DT_Session_2017-07-27_11-24-32"
end tell
tell application "Capture One 10"
activate
«data aevt646C65320000000061657674000001BC00000000000000000000013C0000000400000002000000000000000000000000636F7265636C6F730059499B00600000E05823000060000060572300006000004058230000600000805823000060000060582300006000008056230000600000E0572300006000000058230000600000C057230000600000E0522300006000006165767400010001637369676D61676E00000004000100007472616E6C6F6E6700000004000000006164647270736E200000000800000000001131137462736370736E20000000080000000000000000696E74656C6F6E670000000400000070726570716C6F6E6700000004000000007462736370736E2000000008000000000000000072656D6F6C6F6E67000000040000000066726F6D70736E2000000008000000000012F12F667265636C6F6E6700000004000000003B3B3B3B757372666C697374000000240000000200000000757478740000000C0073006100760069006E006766616C73000000002D2D2D2D6F626A20000000440000000400000000666F726D656E756D00000004696E647877616E747479706500000004646F637573656C646162736F00000004616C6C2066726F6D6E756C6C00000000»
make new document with properties {name:"DT_Session_2017-07-27_11-24-32", path:"/Volumes/WORKING/Sessions/"}
get name of current document
get kind of current document
get every document whose name = "DT_Session_2017-07-27_11-24-32.cosessiondb" and kind = session
end tell
tell application "System Events"
exists folder "/Volumes/WORKING/Sessions/DT_Session_2017-07-27_11-24-32Transfer:"
make new folder at folder "/Volumes/WORKING/Sessions/DT_Session_2017-07-27_11-24-32" with properties {name:"Transfer"}
set frontmost of process "Capture One 10" to true
click menu item "DT_Product_Workspace" of menu 1 of menu item "Workspace" of menu 1 of menu bar item "Window" of menu bar 1 of process "Capture One 10"
set frontmost of process "Capture One 10" to true
click menu item "Edit Keyboard Shortcuts…" of menu 1 of menu bar item "Capture One 10" of menu bar 1 of process "Capture One 10"
set frontmost of process "Capture One 10" to true
click pop up button 1 of window "Edit Keyboard Shortcuts" of process "Capture One 10"
click menu item "Shopbop_Keyboard" of menu 1 of pop up button 1 of window "Edit Keyboard Shortcuts" of process "Capture One 10"
click button "Close" of window "Edit Keyboard Shortcuts" of process "Capture One 10"
end tell
tell application "Capture One 10"
get name of document "DT_Session_2017-07-27_11-24-32.cosessiondb"
set capture name format of item 1 of every document to "Name/_/2 Digit Counter"
set capture counter of document "DT_Session_2017-07-27_11-24-32.cosessiondb" to 0
end tell
tell application "System Events"
set frontmost of process "Capture One 10" to true
click menu item "Output" of menu 1 of menu item "Select Tool Tab" of menu 1 of menu bar item "View" of menu bar 1 of process "Capture One 10"
end tell
tell application "Capture One 10"
exists recipe "A3 300dpi Print ready" of document "DT_Session_2017-07-27_11-24-32.cosessiondb"
set enabled of recipe "A3 300dpi Print ready" of document "DT_Session_2017-07-27_11-24-32.cosessiondb" to false
exists recipe "JPEG sRGB 1600px for web" of document "DT_Session_2017-07-27_11-24-32.cosessiondb"
set enabled of recipe "JPEG sRGB 1600px for web" of document "DT_Session_2017-07-27_11-24-32.cosessiondb" to false
exists recipe "JPEG sRGB QuickProof (preview size)" of document "DT_Session_2017-07-27_11-24-32.cosessiondb"
set enabled of recipe "JPEG sRGB QuickProof (preview size)" of document "DT_Session_2017-07-27_11-24-32.cosessiondb" to false
exists recipe "JPEG sRGB" of document "DT_Session_2017-07-27_11-24-32.cosessiondb"
set enabled of recipe "JPEG sRGB" of document "DT_Session_2017-07-27_11-24-32.cosessiondb" to false
exists recipe "TIFF Adobe RGB (1998) (8bit)" of document "DT_Session_2017-07-27_11-24-32.cosessiondb"
set enabled of recipe "TIFF Adobe RGB (1998) (8bit)" of document "DT_Session_2017-07-27_11-24-32.cosessiondb" to false
exists recipe "SHOPBOP JPEG 100% (sRGB)" of document "DT_Session_2017-07-27_11-24-32.cosessiondb"
set enabled of recipe "SHOPBOP JPEG 100% (sRGB)" of document "DT_Session_2017-07-27_11-24-32.cosessiondb" to true
set output format of recipe "SHOPBOP JPEG 100% (sRGB)" of document "DT_Session_2017-07-27_11-24-32.cosessiondb" to JPEG

Result:
error "Capture One 10 got an error: Connection is invalid." number -609

SeanMurp
 
Posts: 71
Joined: Wed Nov 02, 2016 4:30 am

Re: Capture One Crashes While AppleScript Runs

Postby Eric Nepean » Thu Jul 27, 2017 5:51 pm

I go the zip, thanks.

One thing I see from the events was that a new recipe was not created - that event did not occur. I think your crash may be occurring when you try to update a recipe which already existed at the start of the Applescript. Why? not sure.

One thing that comes to mind is that the crashes seem to be intermittant - some times they occur, sometimes not. Could make vs existing be the differentiator between crash and not crash?

Try changing the code as below to further differentiate the cause of the crash.

You have
Code: Select all
if not (exists recipe "SHOPBOP JPEG 100% (sRGB)" of current document) then make new recipe of current document with properties {name:"SHOPBOP JPEG 100% (sRGB)"}
      --Basic tab
      set enabled of recipe "SHOPBOP JPEG 100% (sRGB)" of current document to true
      --sometimes crashes at this point
      set output format of recipe "SHOPBOP JPEG 100% (sRGB)" of current document to JPEG
      -- more recipe settings


Try this
Code: Select all
if not (exists recipe "SHOPBOP JPEG 100% (sRGB)" of current document) then
      make new recipe of current document with properties {name:"SHOPBOP JPEG 100% (sRGB)"}
      --Basic tab
      set enabled of recipe "SHOPBOP JPEG 100% (sRGB)" of current document to true
      set output format of recipe "SHOPBOP JPEG 100% (sRGB)" of current document to JPEG
      -- more recipe settings
else
      --Basic tab
      set enabled of recipe "SHOPBOP JPEG 100% (sRGB)" of current document to true
      set output format of recipe "SHOPBOP JPEG 100% (sRGB)" of current document to JPEG 
      -- more recipe settings
end if
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: Capture One Crashes While AppleScript Runs

Postby Eric Nepean » Thu Jul 27, 2017 6:24 pm

Hi Sean

I replicate your problem.

Trying to set the Output format to JPEG in an already existing recipe in a session causes COP to crash. The same works OK in a catalog.

I have raised case 257864 with support, you should do the same.

Code: Select all
tell application "Capture One 10"
   set {current_doc_name, current_doc_kind} to (get {name, kind} of current document)
   set current_doc_abs_list to (get every document whose name is current_doc_name and kind is current_doc_kind)
   
   set current_doc_kind to current_doc_kind as string
   --if current_doc_kind ≠ "catalog" then error
   
   set number_of_hits to count of current_doc_abs_list
   if number_of_hits = 0 then
      error "Could not find find " & current_doc_kind & current_doc_name
   else if number_of_hits > 1 then
      error "Found more than one " & current_doc_kind & " with the name " & current_doc_name
   else
      set current_doc_abs to item 1 of current_doc_abs_list
   end if
   
   tell current_doc_abs
      get name of every recipe
      
      get output format of recipe "JPEG sRGB"
      
      log {class of result}
      set output format of recipe "JPEG sRGB" to JPEG
      
   end tell
end tell
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: Capture One Crashes While AppleScript Runs

Postby SeanMurp » Thu Jul 27, 2017 7:44 pm

Thanks for helping Eric. I had already created a support ticket (257696) but will put a reference to this forum thread and your ticket.

I might see about moving away from creating the recipe each time, moving it behind the scenes to the user's recipe folder and just asking the team to manually choose that recipe when working. If taking this bit of code out prevents the repetitive crashes I'm pretty sure that will be the preferred user experience.

Thanks again,
Sean
SeanMurp
 
Posts: 71
Joined: Wed Nov 02, 2016 4:30 am

Re: Capture One Crashes While AppleScript Runs

Postby Eric Nepean » Fri Jul 28, 2017 2:12 am

SeanMurp wrote:Thanks for helping Eric. I had already created a support ticket (257696) but will put a reference to this forum thread and your ticket.

I might see about moving away from creating the recipe each time, moving it behind the scenes to the user's recipe folder and just asking the team to manually choose that recipe when working. If taking this bit of code out prevents the repetitive crashes I'm pretty sure that will be the preferred user experience.

Thanks again,
Sean


I got a reply to my ticket that "Phase One does not offer any official support for scripting"
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: Capture One Crashes While AppleScript Runs

Postby SeanMurp » Tue Aug 01, 2017 8:05 pm

I got a response that is more helpful:

Diggin ginto the code, it is reproducible on occasion- as you said, never the first time and always right when specifying an existing recipe format to JPEG (which makes sense, considering your recipe is created the first go-round without issue). I also can't get the crash to happen when changing the property to TIFF, which is a bit telling as well. However, if I isolate that recipe check/creation section and run it alone.

The crash doesn't occur. Is it the same in your environment?

As you'd mentioned in the forum, it may be better to create/copy the recipe xml outside of the Capture One tell. Or, it might not be the prettiest code to simply trash the existing Shop Bop recipe, and create the recipe anew every time, rather than check if it exists already.

Let me know what you find, this is an interesting case indeed.


I ended up moving our pre-made recipe into the user's library and now just disable the default recipes and enable our custom recipe. Seems to be working much better and without crashes.
SeanMurp
 
Posts: 71
Joined: Wed Nov 02, 2016 4:30 am


Return to Scripting



Who is online

Users browsing this forum: No registered users and 1 guest