メインコンテンツへスキップ

⚠️ Please note that this topic or post has been archived. The information contained here may no longer be accurate or up-to-date. ⚠️

Applescript applicability question

コメント

12件のコメント

  • Eric Valk

    Yes, no problem.

    Check out Script Debugger (you can get a free trial) and open the Dictionary window, it's waaaay more useful than Script Editor. From there you can also the current values of object properties like Path and IPTC fields.

    1
  • Permanently deleted user

    Thanks for the tip. Script Debugger is great. I haven't coded in years but actually cobbled together a script to extract text from the path and it works. Struggling to update an existing IPTC field at the moment.  Hopefully I can fight through that today. 

     

    0
  • Permanently deleted user

    Ericnepean,

    I got the script almost working. I can grab the path, parse it, get the 'year' out of it (which is part of the path) and place that in an empty IPTC field.  That's the good news.

    What is the best/simplest way to loop through all the "selected variants" (e.g say I select 20 variants) and repeat the parse and then IPTC update on each variant.  Tried a few things and am struggling (seems to loop through but am only apparently updating the first variant, not the rest).

    Thanks in advance. Script Debugger is great, BTW. 

    0
  • Permanently deleted user

    Nevermind, figured out my looping challenge. Works like a charm.  I was actually looping correctly but my code to update the correct needed tweaking. 

    0
  • Eric Valk
    Here is how I would do it
    use AppleScript version "2.4" -- Yosemite (10.10) or later
    use scripting additions
    tell application "Capture One 20" to set variantList to variants whose selected is true

    repeat with theVariant in variantList
    tell application "Capture One 20" to tell theVariant to tell its parent image to set thePath to its path
    set theFolder to item -2 of (splitStringToList(thePath, "/"))
    tell application "Capture One 20" to tell theVariant to set its content category to theFolder
    end repeat


    on splitStringToList(theString, theDelim)
    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

     

    0
  • Permanently deleted user

    I did something very similar though definitely not as concise. 

    I ended up putting the string parsing logic in the main repeat loop as I kept getting an error with it outside.  Is it important for the splitStringToList proc to be beneath the repeat/end repeat loop?  

    Also, will it run faster if the splitStringToList is configured as as separate procedure (from a run speed perspective) rather than just putting its code in the repeat loop?

    I've run it on some small sets (<100 images) and large sets (2,500 images) and it slows way down on the large sets.  I assume it has to do with the number of variants being loaded in up front.

     

    0
  • Eric Valk

    Hi Peter

    Is it important for the splitStringToList proc to be beneath the repeat/end repeat loop?

    No, for handlers order doesn't matter. If you declare a script within your script or within a handler, order matters - but we are not doing that here.

    Also, will it run faster if the splitStringToList is configured as as separate procedure (from a run speed perspective) rather than just putting its code in the repeat loop?

    Aha, by "proceedure" you mean "handler". I have found very little difference in speed comparing code in handlers to code in the main script. The reason I put this in a handler is that this is a function I use over and over again. I have a library of "utility" handlers that have been refined and tested; this one of them.

    I've run it on some small sets (<100 images) and large sets (2,500 images) and it slows way down on the large sets.

    I have found that the speed of Applescripts when handling large numbers of variants or images is mainly limited by the number of Applescript messages sent to Capture One (or other applications). My main catalog has 16,000 images and this really makes itself felt. It is much faster to ask Capture One for a list of information rather than to ask for information about each variant separately. Filtering also slows things down: "get ID of Variants whose selected is true" is slower than "get ID of Variants".

    Some types of information are faster to obtain: "get ID of variant" is typically the fastest, "get path of (parent image of (variants whose selected is true)) will be fairly slow.

    Here is another version which should be faster as I've changed the code to get the path information for all the variants at once. I haven't speed tested as this is not somethinng I wish to do with my Main Catalog.

    use AppleScript version "2.4" -- Yosemite (10.10) or later
    use scripting additions

    tell application "Capture One 20"
    variantList to variants whose selected is true
    set variantPathList to path of (parent image of (variants whose selected is true))
    end tell


    set vCtr to 1
    repeat with theVariant in variantList
    set thePath to its variantPathList's item vCtr
    set theFolder to item -2 of (splitStringToList(thePath, "/"))
    tell application "Capture One 20" to tell theVariant to set its content category to theFolder
    set vCtr to vCtr + 1
    end repeat


    on splitStringToList(theString, theDelim)
    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

     

     

     

    0
  • Permanently deleted user

    That's great, thanks so much and I'm learning a lot. Couple things. I actually want to grab two fields from the path and put those values in two places in IPTC. (these will be used later for a giant JPG producing process recipe I'm gonna run).  

    I took your latest version and tweaked to do two things.

    • If the Path being dissected is long enough (if there are enough subdirectories in it) then I get the second value, if not, I skip it. Why? Well, my folder structure goes back 15 years and I wasn't always consistent how deep I went. I always went to ...\yyyy and many times I went to ..\yyyy\yyyymm . In the case of the latter, I want to grab both folders . Anyway, what I did was just modify your code a bit.
    • I also added a "display notification" so I could see how it was running. That may, however, slow it down... I'm not sure. But I wanted to get a feel for how far along this thing is at any point in time.

    Anyway, here's my version after tweaks....

    Thanks again.

     

     

    0
  • Permanently deleted user

    Last thing: performance is 10x as fast as my first try.  I just processed 1700 variants in 2:44 which is over 10/second.  My previous version, which did not pre-fetch all the paths , was running more like 1 per second. Not sure if your first version would have been as slow, but this latest version is clearly the best method.

    0
  • Eric Valk

    Good stuff. There are a couple of things to be aware of when you do a prefetch with a very large number of variants, e.g. >10,000,

    You may be unable to save the Script, because Script Editor tries to save the script and all the global variables. All variables in the main script are global by default, and a very large list can cause a stack overflow when you try to save the script. The simplest solution is to put all the large list handling in a handler, and for good measure, declare the large lists as local. Another solution is to set the large variable to null when you are done using it.

    Another thing that may happen is that the AppleScript command prefetching the data times out. The default time out is 60 seconds IIRC. What happens on a timeout is that the Script has an error, but Capture One goes on processing the request and is busy until its done. Applescript has a with timeout command that allows you to set a longer timeout for a command.

    0
  • Eric Valk

     A comment on your use of IPTC fields.

    It useful to use ones grouped togther in Capture One's Metadata Tool, Job Identifier and Content Category are at opposite ends.

    If there were any Titles assigned in your image colllection, they will show up in Content Description, right next to Content Category at the top of the list.

    Content supplemental categories is beside it and would logically map to your subcategory, (You can put multiple values in this field like this "subcat1, subcat2, subcat3").

     

     

    0
  • Permanently deleted user

    Good point. I'll look at it again.  I need the field to also be usable in the process recipe output naming as a token. But I will explore a bit more before I commit.

    Thanks again.

    0

投稿コメントは受け付けていません。