Duplicate last variant

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

Duplicate last variant

Postby Pat78 » Tue Oct 09, 2018 9:10 am

Hi all,
I'm testing an simple script which should duplicate the last variant to a specific folder after capture.

This is the Capture done script:
Code: Select all
tell application "Capture One 11"
   set capture done script to alias "Macintosh HD:Users:Shared:Scripts:Backup.scpt"
end tell


It will trigger this script but i'm doing something wrong:
Code: Select all
tell application "Capture One 11" to tell current document
   set theVariant to the last variant
   set backupFolder to alias "Macintosh HD:Users:fotograaf:Desktop:BackUp"
   duplicate theVariant to backupFolder
end tell


Can a someone tell me what i'm doing wrong? :(

Thanks Patrick
Pat78
 
Posts: 22
Joined: Tue Sep 19, 2017 10:00 am

Re: Duplicate last variant

Postby HansB » Tue Oct 09, 2018 3:36 pm

I think you need to use the 'parent image' for that, not the 'variant'. But I'm not sure, and I cannot test it right now.
Maybe you can give it a try.


Regards,
Hans
HansB
 
Posts: 875
Joined: Fri Sep 25, 2009 2:59 pm

Re: Duplicate last variant

Postby Eric Nepean » Tue Oct 09, 2018 6:14 pm

I don't find a "duplicate" command in Capture One's Applescript dictionary.

Finder has a "duplicate" command, and handles aliases.

I think what you may want to do is to extract the path of the image file from Capture One, and then tell Finder to duplicate it.
Code: Select all
 ## untested but similar to code I have written
tell application "Capture One 11" to set theImageFilePath to get path of parent image of the last variant

tell application "Finder"
   set backupFolder to alias "Macintosh HD:Users:fotograaf:Desktop:BackUp"
   duplicate theImageFilePath to backupFolder
end tell
Cheers, Eric
[late 2015 iMac, 4GHz i7, 24GB RAM, external SSDs. GX8, E-M1, GX7, GM5, GM1 ....]
Eric Nepean
 
Posts: 249
Joined: Sat Oct 25, 2014 8:02 am

Re: Duplicate last variant

Postby Pat78 » Wed Oct 10, 2018 8:53 am

Thanks Eric and Hans,

I will test it. Thanks again!

Patrick
Pat78
 
Posts: 22
Joined: Tue Sep 19, 2017 10:00 am

Re: Duplicate last variant

Postby Pat78 » Wed Oct 10, 2018 10:15 am

Hi Eric,

I've tested the script but it is giving me this error

[img]Schermafbeelding%202018-10-10%20om%2011.07.27[/img]

it says: Handler could not run objects of this class

Do you know how to fix this?

Thanks Patrick
Pat78
 
Posts: 22
Joined: Tue Sep 19, 2017 10:00 am

Re: Duplicate last variant

Postby Eric Nepean » Wed Oct 10, 2018 12:06 pm

Hi Patrick

It took some debugging but this works. Applescript has many complex ways to represent a file and navigating them is tricky.

Code: Select all
##_ps indicates the string representation of the path in POSIX form
##_as indicates the string representation of the path in alias form
tell application "Capture One 11" to set theImageFilePath_ps to get path of parent image of primary variant
set backupFolder_as to (get path to desktop folder) & "Backup" as string
set theImageFile_as to get (get alias POSIX file theImageFilePath_ps) as string
tell application "Finder" to duplicate file theImageFile_as to folder backupFolder_as with replacing
Cheers, Eric
[late 2015 iMac, 4GHz i7, 24GB RAM, external SSDs. GX8, E-M1, GX7, GM5, GM1 ....]
Eric Nepean
 
Posts: 249
Joined: Sat Oct 25, 2014 8:02 am

Re: Duplicate last variant

Postby Pat78 » Wed Oct 10, 2018 1:05 pm

You're a genius Eric! this works.
This was way to complex for me but I keep on learning.

Thanks a lot!

Patrick
Pat78
 
Posts: 22
Joined: Tue Sep 19, 2017 10:00 am

Re: Duplicate last variant

Postby Eric Nepean » Wed Oct 10, 2018 6:45 pm

I keep on learning too, as I do this.

BTW, Google search is a great tool, e.g. search for “AppleScript finder duplicate example”, hits from Stackexchange and MacScripter are often quite informative. MacScripter forum has many of the really deep AppleScript coders as members and you can get really good advice here.
Cheers, Eric
[late 2015 iMac, 4GHz i7, 24GB RAM, external SSDs. GX8, E-M1, GX7, GM5, GM1 ....]
Eric Nepean
 
Posts: 249
Joined: Sat Oct 25, 2014 8:02 am

Re: Duplicate last variant

Postby Pat78 » Wed Oct 10, 2018 8:44 pm

Thanks! I know Stackexchange indeed. Posted some questions on Stackexchange before, really helpfull applescripting for Capture One is still a bit specific.

I've been playing around with your last script and made some changes to make it more flexible, by asking with a prompt for a backup folder. I only tried it by running it from the scripteditor,but running it with an capture done script, It will ask you to choose a backup folder when you shoot you're first image. After that you can keep shooting and the script will duplicate the images to that specific folder.

What I want is when the backup folder is deleted or when you start a new Session, it should ask you to choose a new backup folder. But it does not exactly what I want at the moment. See script below.

It works fine the first tim you run it. eWhen you delete your previous made backup folder and empty your trash. The script gives an error that it cannot find the backup folder but it is not asking to choose a new backup folder (What I want when the backup folder is missing). When you click on "Compile" again in the script editor it works fine again and it is asking for a new backup folder..

See this script maybe you can try it:

Code: Select all
##_ps indicates the string representation of the path in POSIX form
##_as indicates the string representation of the path in alias form
property backupFolder_as : ""

tell application "Capture One 11" to set theImageFilePath_ps to get path of parent image of primary variant
if backupFolder_as = "" then
   set backupFolder_as to choose folder with prompt "Select backup folder:" as string
else
   try
      --if the script has a property that has been deleted (i.e., the backup folder), it will cause
      --an error that resolves by asking for a new folder
      set backupFolder_as to backupFolder_as as alias
   on error
      set backupFolder_as to choose folder with prompt "Select backup folder:"
   end try
end if
set theImageFile_as to get (get alias POSIX file theImageFilePath_ps) as string
tell application "Finder" to duplicate file theImageFile_as to folder backupFolder_as with replacing
Pat78
 
Posts: 22
Joined: Tue Sep 19, 2017 10:00 am

Re: Duplicate last variant

Postby Eric Nepean » Thu Oct 11, 2018 4:18 am

Hi ans
Since I arrive home late I don't have a chance to fully debug this scrript.

But one thing that I notice immediately is this line
Code: Select all
set backupFolder_as to choose folder with prompt "Select backup folder:" as string
Adding a log statement I verified that the variable/property backupFolder_as is class "alias" not class "text". The as string command only converts "Select backup folder:" to a string (which it already was)

The way Applescript works is that once defined, an alias always points to the same file or folder, even if you move it and I think even if you rename it. I think it is actually a reference to the inode of the file. (For this reason, an alias can only be defined for a file or folder which already exists. The string can be written, but trying to convert it to type alias will fail.)

Now what happens when I use the script to create a Backup folder, use it a few times and then delete it, the i]Backup[/i] folder is moved to Trash. But it still exists, and has the same inode. The next time I run the script, it copies the image file to the Backup folder in the Trash. :lol: :lol: Not useful.

Then if you empty the Trash, the alias refers to a folder that doesn't exist, and the final line that uses backupFolder_as as a target location crashes.

So the first fix is to rewrite that line like this
Code: Select all
set backupFolder_as to get (choose folder with prompt "Select backup folder:") as string
Now choose folder creates an alias, which is immediately converted to a string. Now when the folder is deleted, the alias does not follow to the Trash.

This far I have debugged.

Then I think after the else statement, I would modify the try structure like this
Code: Select all
   try
      --if the previously created backup folder has been deleted or moved, the alias cannot be created
      --the error that results causes the script to ask for a new folder
      get backupFolder_as as alias
   on error
      set backupFolder_as to get (choose folder with prompt "Select backup folder:") as string
   end try
Cheers, Eric
[late 2015 iMac, 4GHz i7, 24GB RAM, external SSDs. GX8, E-M1, GX7, GM5, GM1 ....]
Eric Nepean
 
Posts: 249
Joined: Sat Oct 25, 2014 8:02 am

Re: Duplicate last variant

Postby Pat78 » Thu Oct 11, 2018 1:37 pm

Hi Eric,

I've made the changes and tested it. From the Scripteditor it works fine! But when it is triggered by a capture done script it is prompting for an backup after every shot now.. Help :-)

Patrick
Pat78
 
Posts: 22
Joined: Tue Sep 19, 2017 10:00 am

Re: Duplicate last variant

Postby Eric Nepean » Thu Oct 11, 2018 4:48 pm

Hi Patrick
I think what may be happening is that the property value is reset when Capture done script. Hard to know. And I don't have a camera for tethered shooting.

I will look at it in more detail this evening.

Can you change the two dialogs for "choose folder" so that they are slightly different, perhps add a "1" in the title of one, and "2" in the other title.

Then tell me which dialog is being triggered, the one triggered by the property as "" or the one triggered by failure of the alias to be created.

From there we can devise a fix.
Cheers, Eric
[late 2015 iMac, 4GHz i7, 24GB RAM, external SSDs. GX8, E-M1, GX7, GM5, GM1 ....]
Eric Nepean
 
Posts: 249
Joined: Sat Oct 25, 2014 8:02 am

Re: Duplicate last variant

Postby Pat78 » Thu Oct 11, 2018 7:42 pm

Hi Eric,

I changed the dialogs as you said. The one which is triggered over and over again when shooting tethered is the first line triggered by the property. So I think it has something to do with the capture done.

This is how the code looks now:
Code: Select all
property backupFolder_as : ""

tell application "Capture One 11" to set theImageFilePath_ps to get path of parent image of primary variant
if backupFolder_as = "" then
   set backupFolder_as to get (choose folder with prompt "Select backup folder 1:") as string
else
   try
      --if the previously created backup folder has been deleted or moved, the alias cannot be created
      --the error that results causes the script to ask for a new folder
      get backupFolder_as as alias
   on error
      set backupFolder_as to get (choose folder with prompt "Select backup folder 2:") as string
   end try
end if
set theImageFile_as to get (get alias POSIX file theImageFilePath_ps) as string
tell application "Finder" to duplicate file theImageFile_as to folder backupFolder_as with replacing


This is the capture done script which is triggering, pretty simple:
Code: Select all
tell application "Capture One 11"
set capture done script to alias "Macintosh HD:Users:Shared:Scripts:Backup.scpt"
end tell


When triggering from the scripteditor it works perfect. After removing the specific folder, it triggers the second line by the failure.

Thanks,

Patrick
Pat78
 
Posts: 22
Joined: Tue Sep 19, 2017 10:00 am

Re: Duplicate last variant

Postby Eric Nepean » Fri Oct 12, 2018 5:16 am

Hmmmm a properties life (value is not reset) is until the script is recompiled. Since the script specified in the capture done handler is a "scpt" it is not complied - and therefore compiled everytime it is called.

If the script is compiled and saved as an ".app", and the Capture Done Handler is modified to call the the compiled script, it should work as expected.

In Script Editor, choose "Save "As" and then set File Format to be "Application"
Cheers, Eric
[late 2015 iMac, 4GHz i7, 24GB RAM, external SSDs. GX8, E-M1, GX7, GM5, GM1 ....]
Eric Nepean
 
Posts: 249
Joined: Sat Oct 25, 2014 8:02 am

Re: Duplicate last variant

Postby Pat78 » Sat Oct 13, 2018 8:28 pm

Hi Eric, No succes..
I've compiled the script and saved it as an .app and i've modified the capture done script to trigger the .app.
But same thing is happening.

Also tried to save it as an compiled run only script, but same thing happening.

When I just double click on the .app to duplicate the parent image, it does exactly what I want. But when triggered by the capture done script it goes wrong. So it has to be something to do with the capture done script.

Can the "alias" in the script be the problem? Is there another way to write the capture done script shown below?

Code: Select all
tell application "Capture One 11"
   set capture done script to alias "Macintosh HD:Users:Shared:Scripts:Backup.app"
end tell


Thanks Patrick
Pat78
 
Posts: 22
Joined: Tue Sep 19, 2017 10:00 am

Next

Return to Scripting



Who is online

Users browsing this forum: No registered users and 1 guest