Create new session using template?

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

Create new session using template?

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

Anyone know if you can programmatically create a new session using a pre-made session template? There doesn't seem to be anything in the Capture One AppleScript dictionary that relates to this. It is not necessary for our workflow but would be a nice to have.

In case anyone wants/needs it, our current create new session code (session name and session path are pre-defined in a separate part of our script):
Code: Select all
tell application "Capture One 10"
               activate
               close every document without saving
               set newDoc to make new document with properties {name:sessionName, path:sessionFolderPath}
            end tell
SeanMurp
 
Posts: 78
Joined: Wed Nov 02, 2016 4:30 am

Re: Create new session using template?

Postby NNN635219644899555657 » Thu Apr 05, 2018 7:11 pm

Hi, Sean.

I lifted your code and made this:

Code: Select all
set sessionFolderPath to "Macintosh HD:Users:Br415a8:Desktop"
set sessionName to "Bobo"
tell application "Capture One 11"
   activate
   close every document without saving
   set newDoc to make new document with properties {name:sessionName, path:sessionFolderPath}
end tell


But I get this error. Not sure what to do?

error "Capture One 11 got an error: Cannot set because there is no file at this location." number -43
NNN635219644899555657
 
Posts: 11
Joined: Fri Dec 06, 2013 11:08 pm

Re: Create new session using template?

Postby SeanMurp » Thu Apr 05, 2018 8:53 pm

Hi Bret,
Should be a really easy fix to get it working. Use the POSIX path for the sessionFolderPath instead of the HFS path. So in this case it should be:
Code: Select all
set sessionFolderPath to "/Users/Br415a8/Desktop/"
set sessionName to "Bobo"
tell application "Capture One 11"
   activate
   close every document without saving
   set newDoc to make new document with properties {name:sessionName, path:sessionFolderPath}
end tell
SeanMurp
 
Posts: 78
Joined: Wed Nov 02, 2016 4:30 am

Re: Create new session using template?

Postby SeanMurp » Thu Apr 05, 2018 8:54 pm

We have also added in a System Events check to make sure the folder doesn't already exist. If it does exist then the user is prompted with a dialog asking if they want to replace or name differently.
SeanMurp
 
Posts: 78
Joined: Wed Nov 02, 2016 4:30 am

Re: Create new session using template?

Postby Jim_DK » Thu Apr 19, 2018 3:38 pm

You can now do this in 11.1 using pre-saved templates.
Jim_DK
Crew
Crew
 
Posts: 659
Joined: Thu Dec 03, 2009 10:00 pm

Re: Create new session using template?

Postby SeanMurp » Thu Apr 19, 2018 4:21 pm

Great! Just updated and can't wait to give it a try.
SeanMurp
 
Posts: 78
Joined: Wed Nov 02, 2016 4:30 am

Re: Create new session using template?

Postby LPb » Sat Feb 23, 2019 1:45 pm

I'm trying a similar thing here, but I can't get it to work.
I created a template called shoot.cosessiontemplate and saved it in the bundle under resources folder.
I defined sessionLoc, sessionName and then I try to use following code to create the session, but I keep getting errors.
Tried using POSIX path as well but I still get errors saying can't find template..
Any suggestions?

CO v12
error message: "Capture One 12 got an error: No template of this name exists for this kind of document." number -2710 from document to class

Code: Select all
set templateFile to path to resource "shoot.cosessiontemplate"

tell application "Capture One 12"
   make new document with properties {path:sessionLoc, name:sessionName, template:templateFile}
end tell


full code I have so far:
Code: Select all
set sessionLoc to choose folder

set {year:yy, month:mm, day:dd} to (current date)
if mm as number < 10 then
   if dd < 10 then
      set Today to (yy - 2000 & 0 & (mm as number) & 0 & dd) as string
   else
      set Today to (yy - 2000 & 0 & (mm as number) & dd) as string
   end if
else
   if dd < 10 then
      set Today to (yy - 2000 & (mm as number) & 0 & dd) as string
   else
      set Today to (yy - 2000 & (mm as number) & dd) as string
   end if
end if
set Today to the text returned of (display dialog "Date" default answer Today)

set shootName to the text returned of (display dialog "Shoot" default answer "")
set folderPrefix to the text returned of (display dialog "Shot folders prefix" default answer "")


set sessionName to Today & "_" & shootName as string
display alert "Session '" & sessionName & "' will be created" message POSIX path of sessionLoc

set templateFile to path to resource "shoot.cosessiontemplate"

tell application "Capture One 12"
   make new document with properties {path:sessionLoc, name:sessionName, template:(POSIX path of templateFile as text)}
end tell

LPb
 
Posts: 8
Joined: Mon Feb 09, 2015 9:31 pm
Location: Belgium

Re: Create new session using template?

Postby Eric Nepean » Sat Feb 23, 2019 3:20 pm

I think yout problem may be with the us of "path to resource".

I see a note here https://www.oreilly.com/library/view/applescript-the-definitive/0596102119/re74.html
that says this doesn't work with Script Editor.

I also wonder which application's resource folder you have put the template in, is it Capture One or the Script Bundle?

If in the Script, the Script has to be a Script Bundle, that is a .scptd file, not a .scpt file.

If in Capture One (I wouldn't recommend this), you need to include the "In Bundle ... " part of the command

I recommend you open the Applescript Dictionary for Standard Additons, and search for "Path To"

As a debugging move, perhaps create a file "Resources" on your desktop, refer to that, and see if your script will work.

As you develop your Script you might consider alternatives for storing your template, for example
~/Library/Preferences/CaptureOneTemplates

Code: Select all
get (path to preferences folder as string) & "CaptureOneTemplates"
Eric Nepean
 
Posts: 637
Joined: Sat Oct 25, 2014 8:02 am
Location: Ottawa

Re: Create new session using template?

Postby LPb » Sat Feb 23, 2019 3:39 pm

Thank you for the tips Eric,

I am working in a script bundle and I have the template file directly under the resources folder.

My main goal is to have a standalone app that I can share between different computers, so that it sets up a session with my desired session template. Ultimately I would also like it to load certain process recipes that i will include in the resources folder.
LPb
 
Posts: 8
Joined: Mon Feb 09, 2015 9:31 pm
Location: Belgium

Re: Create new session using template?

Postby Eric Nepean » Sun Feb 24, 2019 6:24 am

I tried different variations, but no way I could get "path to resource" to work on a script bundle that Script Editor is running.

What I could get to work is this:

I copied a file I happened to have on my desk top inside the resources folder of a test Script (bundle).
I noticed that a file "description.rtfd" was already present.

The Test script is this:
Code: Select all
set theAPath to (path to resource "description.rtfd") as string -- this works

set theScriptPath to get path to me
set theResourcePath_S to (theScriptPath as text) & "Contents:Resources:" & "ericscomputer.txt"
get alias theResourcePath_S -- this works

set theEPath to (path to resource "ericscomputer.txt") as string -- this doesn't work
Eric Nepean
 
Posts: 637
Joined: Sat Oct 25, 2014 8:02 am
Location: Ottawa

Re: Create new session using template?

Postby LPb » Sun Feb 24, 2019 10:44 pm

I found the solution to my problem!
The document 'template' property expects a text input (the template filename, without file extension) and NOT a file or filepath, it then looks for that template in the default templates folder for Capture One.

So what i do now,
I first tell finder to copy my template file from the bundle resources folder to ~/Library/Application Support/Capture One/Templates
And then call on the template when creating the new document.

I also learned that specifying a template when creating a new document only works if you specify the document kind as a session.

Code: Select all
set theTemplateFile to (path to resource "script-template.cosessiontemplate")
tell application "Finder"
   copy file theTemplateFile to folder ((path to home folder as string) & "⁩Library⁩:Application Support⁩:Capture One:Templates⁩")
end tell

tell application "Capture One 12"
   make new document with properties {kind:session, path:sessionLoc, name:sessionName, template:"script-template"}
end tell
LPb
 
Posts: 8
Joined: Mon Feb 09, 2015 9:31 pm
Location: Belgium

Re: Create new session using template?

Postby Eric Nepean » Mon Feb 25, 2019 12:11 pm

NNN635591107104249611 wrote:I found the solution to my problem!
The document 'template' property expects a text input (the template filename, without file extension) and NOT a file or filepath, it then looks for that template in the default templates folder for Capture One.

So what i do now,
I first tell finder to copy my template file from the bundle resources folder to ~/Library/Application Support/Capture One/Templates
And then call on the template when creating the new document.

I also learned that specifying a template when creating a new document only works if you specify the document kind as a session.

Code: Select all
set theTemplateFile to (path to resource "script-template.cosessiontemplate")
tell application "Finder"
   copy file theTemplateFile to folder ((path to home folder as string) & "⁩Library⁩:Application Support⁩:Capture One:Templates⁩")
end tell

tell application "Capture One 12"
   make new document with properties {kind:session, path:sessionLoc, name:sessionName, template:"script-template"}
end tell

Good work and thanks for sharing what you have learned!!

Do you run this script from Script Editor or from Capture One? And which version of OSX are you using?
Eric Nepean
 
Posts: 637
Joined: Sat Oct 25, 2014 8:02 am
Location: Ottawa

Re: Create new session using template?

Postby LPb » Mon Feb 25, 2019 2:51 pm

Good work and thanks for sharing what you have learned!!

Do you run this script from Script Editor or from Capture One? And which version of OSX are you using?


I've been running it from the script editor up until now. I also plan on letting the script run first and letting it open and set up the capture one session.

I'm on MacOS Mojave 10.14.2
Capture One v12
LPb
 
Posts: 8
Joined: Mon Feb 09, 2015 9:31 pm
Location: Belgium


Return to Scripting



Who is online

Users browsing this forum: No registered users and 1 guest