How to rename folders inside CaptureOne ??

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

How to rename folders inside CaptureOne ??

Postby NN13765 » Sat May 02, 2020 3:42 pm

This probably sounds like a dumb question and it probably is, but I can't see how to rename a folder insie C1. I need to do it from inside the programme and not use a shell script in Finder so that C1 keeps track of what the folders are called. The bit that is stumping me at the moment is the very first step - selecting the folder to change, and finding its name!

Help gratefully received!
NN13765
 
Posts: 27
Joined: Sun Mar 29, 2009 11:22 am

Re: How to rename folders inside CaptureOne ??

Postby Eric Nepean » Wed May 06, 2020 2:34 pm

In general, you can get a reference to the collection {catalog folder, Album, Smart Album, Group, Project} and its name from this Applescript command:
Code: Select all
tell application "Capture One 20" to tell current document to set {theCollection, theName} to {current collection, current collection's name}
or
Code: Select all
tell application "Capture One 20"
   tell current document
      set theCollection to current collection
      set theName to current collection's name
      set {thePath, thePosixPath} to {null, ""}
      try
         set thePath to current collection's folder
         tell me to set thePosixPath to POSIX path of thePath
      end try
   end tell
end tell

However I know of no way to change the name of a collection or folder using Applescript and Capture One. Capture One's Rename command is not accessible by Applescript. You can't set the name of a collection.

(Perhaps the Move command may do it)

As work around, I would find the folder with Finder, use Finder to change the name, and then use Capture One's relocate caommand (which is scriptable) to find the renamed folder.
Eric Nepean
 
Posts: 677
Joined: Sat Oct 25, 2014 8:02 am
Location: Ottawa

Re: How to rename folders inside CaptureOne ??

Postby NN13765 » Thu May 07, 2020 1:21 pm

Thanks, Eric - even if the news is bad :-) This might actually be one of those cases where you think you'll script something but then it turns out to be quicker just to do it manually. Less fun, of course!
NN13765
 
Posts: 27
Joined: Sun Mar 29, 2009 11:22 am

Re: How to rename folders inside CaptureOne ??

Postby Eric Nepean » Thu May 07, 2020 2:05 pm

I don't see it as that difficult
  • Extract the Folder's Path
  • Tell Finder to rename the folder (you have the path)
  • Tell Capture One to Relocate the Folder (you have the new path)
Eric Nepean
 
Posts: 677
Joined: Sat Oct 25, 2014 8:02 am
Location: Ottawa

Re: How to rename folders inside CaptureOne ??

Postby NN13765 » Thu May 07, 2020 2:48 pm

Eric Nepean wrote:I don't see it as that difficult
  • Extract the Folder's Path
  • Tell Finder to rename the folder (you have the path)
  • Tell Capture One to Relocate the Folder (you have the new path)


We start from different levels of competence :-)
NN13765
 
Posts: 27
Joined: Sun Mar 29, 2009 11:22 am

Re: How to rename folders inside CaptureOne ??

Postby Eric Nepean » Thu May 07, 2020 4:16 pm

Here is an untested script that should do it.

Be careful. Try it first on a test folder with test images you can afford to lose.

Code: Select all
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

set foundAPath to false
tell application "Capture One 20"
   tell current document
      set theCollection to current collection
      set theName to current collection's name
      set {thePath, thePosixPath} to {null, ""}
      try
         set thePath to current collection's folder
         tell me to set thePosixPath to POSIX path of thePath
         set foundAPath to true
      end try
      if foundAPath then set imagelist to theCollection's images
   end tell
end tell

if not foundAPath then error "The collection \"" & theName & "\" does not have a folder"
if {"Desktop", "Documents", "Pictures", "Applications", "Downloads", "Music", "Library", "System", "Movies", "Public"} contains theName then error "Danger: Do not attempt to change the name of \"" & theName & "\""

try
   set newName to text returned of (display dialog "set the file name" default answer "theName")
   get text 8 of newName -- trigger an error if the Newname doesn't have at least 8 characters
on error
   return
end try

tell application "Finder"
   set theFolderAlias to (POSIX file thePosixPath as alias)
   set theFolderAlias's name to newName
   set newFolderPath to POSIX path of theFolderAlias
end tell

tell application "Capture One 20" to tell theCollection
   repeat with anImage in imagelist
      set imageName to anImage's name
      set newImagePath to newFolderPath & imageName
      relink anImage to path newImagePath
   end repeat
end tell
Eric Nepean
 
Posts: 677
Joined: Sat Oct 25, 2014 8:02 am
Location: Ottawa

Re: How to rename folders inside CaptureOne ??

Postby NN13765 » Sun May 10, 2020 9:56 am

I'll try it - thanks so much :-)
NN13765
 
Posts: 27
Joined: Sun Mar 29, 2009 11:22 am

Re: How to rename folders inside CaptureOne ??

Postby Eric Nepean » Sun May 10, 2020 7:55 pm

Here is an improved version.
  • It shows the current folder name correctly
  • does a more accurate job of checking for folders that should not be renamed
  • New Name length check is removed (not needed)
  • Checks that the a folder with the new name does not already exist in the same location

Code: Select all
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

set foundAPath to false
tell application "Capture One 20"
   tell current document
      set theCollection to current collection
      set theName to current collection's name
      set {thePath, thePosixPath} to {null, ""}
      try
         set thePath to current collection's folder
         tell me to set thePosixPath to POSIX path of thePath
         set foundAPath to true
      end try
      if foundAPath then
         set imagelist to theCollection's images
         set thePath_s to thePath as text
      end if
   end tell
end tell

if not foundAPath then error "The collection \"" & theName & "\" does not have a folder"
set dangerFolder to false
try
   set dangerPath to run script "get path to " & theName & " folder"
   if thePath_s = (get dangerPath as text) then set dangerFolder to true
end try
if thePath_s = (get path to home folder as text) then set dangerFolder to true
if dangerFolder then error "Danger: You must not attempt to change the name of the Folder \"" & theName & "\""

set newName to text returned of (display dialog "set the file name" default answer theName)

if (theName = newName) then error "You have not selected a new Folder name"

set folderExists to false
set newPosixPath to joinListToString((items 1 thru -3 of (get splitStringToList(thePosixPath, "/")) & newName), "/") & "/"
try
   set targetFolder_a to (get alias POSIX file newPosixPath)
   set folderExists to true
end try

if folderExists then error "The folder \"" & newName & "\" already exists"

tell application "Finder"
   set theFolderAlias to (POSIX file thePosixPath as alias)
   set theFolderAlias's name to newName
   set newFolderPath to POSIX path of theFolderAlias
end tell

tell application "Capture One 20" to tell theCollection
   repeat with anImage in imagelist
      set imageName to anImage's name
      set newImagePath to newFolderPath & imageName
      relink anImage to path newImagePath
   end repeat
end tell

on splitStringToList(theString, theDelim)
   ## Public Domain
   set theList to {}
   set astid to AppleScript's text item delimiters
   try
      set AppleScript's text item delimiters to theDelim
      set theList to text items of theString
   on error
      set AppleScript's text item delimiters to astid
   end try
   set AppleScript's text item delimiters to astid
   return theList
end splitStringToList

on joinListToString(theList, theDelim)
   ## Public Domain
   set theString to ""
   set astid to AppleScript's text item delimiters
   try
      set AppleScript's text item delimiters to theDelim
      set theString to theList as string
   end try
   set AppleScript's text item delimiters to astid
   return theString
end joinListToString
Eric Nepean
 
Posts: 677
Joined: Sat Oct 25, 2014 8:02 am
Location: Ottawa

Re: How to rename folders inside CaptureOne ??

Postby NN13765 » Mon May 11, 2020 1:42 pm

Hmm - maybe User Error but what happened is that the folder got re-named but the images didn't find their new home and had to be re-linked by hand? Did it work OK for you?
NN13765
 
Posts: 27
Joined: Sun Mar 29, 2009 11:22 am

Re: How to rename folders inside CaptureOne ??

Postby Eric Nepean » Mon May 11, 2020 3:58 pm

NN13765 wrote:Hmm - maybe User Error but what happened is that the folder got re-named but the images didn't find their new home and had to be re-linked by hand? Did it work OK for you?


Hmmm, thats not what I intended. I though that the relinking should do it.

I'll have to set up a special folder first, as I don't want to run this on my working files.

Let me look into it.
Eric Nepean
 
Posts: 677
Joined: Sat Oct 25, 2014 8:02 am
Location: Ottawa


Return to Scripting



Who is online

Users browsing this forum: No registered users and 3 guests