AppleScript and Large Catalogs

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

AppleScript and Large Catalogs

Postby Eric Nepean » Tue Jun 05, 2018 3:53 am

When using Applescript to manipulate large catalogs, you have to be very careful to choose the fastest executing commands to avoid ending up with a script that takes for ever to run.

I've written an Applescript command profiler, so that I can methodically check performance. Here are some results for my catalog of 16250 variants.

1) Some commands execute in under two seconds, even on a big catalog
  • get rating of every variant
  • get id of every variant
  • get count of every variant
  • deselect current document variants (every variant)
2) The command {get every variant} executes in 26 seconds

3) There are commands that require about 30ms per selected variant. The time per variant increases as more variants are selected. If all variants in the catalog have been selected the time rises to 40ms per variant, and the total time is about 10 minutes.
  • get count of selected variants
  • get selected of every variant
  • get selected variants
4) There are another group of commands that require 70ms per selected variant With all variants selected it is about 80ms per variant, and the total execution time is 22 minutes.
  • get every variant whose selected is true
  • get selected variants
5) The command group requires 80 to 85ms per selected variant, for a total execution time of 23 minutes.
  • select COPDocRef variants thisVariantList
  • deselect COPDocRef variants thisVariantList
6) Execution times are even longer for commands that access a single variant, especially with larger numbers of variants selected. To read the whole catalog this way could take 55 minutes.
  • get first variant whose id is firstID
  • get variant 2
  • get selected of variant 2

In order to use these long duration commands one needs to use the the Applescript "with timeout" command. Without this, an Applescriptt command will timeout in 120 seconds. Capture One keeps running until the command is executed, however long that takes, but the Applescript has given up waiting for the answer.
Eric Nepean
 
Posts: 655
Joined: Sat Oct 25, 2014 8:02 am
Location: Ottawa

Re: AppleScript and Large Catalogs

Postby Eric Nepean » Tue Jun 05, 2018 3:57 am

For those who wish to profile their own Macs and their own catalogs, here is the current version of my Capture One command profiler. If you find some interesting results, please do come back and post them.

This script also shows a method to estimate the timeouts required for a catalog for which Applescript command durations are unknown.

Code: Select all
## Notes
-- Applescript to Profile CaptureOne Applescript commands
-- Creates a report in Text Edit
-- *** Operation
-- Open  the compiled and saved file
-- Open the Script Editor log window, and select the messages tab
-- Select only a small number of variants, from any collection

-- Run the script
-- Results appear in the Script Editor Log and Text Edit
-- This script does not write or delete any information in the COP Catalog or Session or the image file
--
-- The user may elect to enable or disable results in Notifications, TextEdit and Script Editor by setting the "enable" variables at beginning of the script
-- The user may change the amount of reporting by setting the "debugLogLevel" and "ResultsFileMaxDebug" variables at beginning of the script
-- If you are having some issues, then set debugLogLevel to 3 and send me the results from Script Editors log window, or Text Edit.

## Values in this section are safe to change, within limits indicated. Support is likely but no commitment
set debugLogLevel to 0 --            0...6 Values >1 result in increasing amounts of debug data that takes grpA_er to report
set ResultsFileMaxDebug to 2 --         1...6  suggest not more than 2


## ***** Not safe to change stuff below this line, unless you have some background in SW development.
## I generally won't help much if you change stuff below this line. I may explain the design intent.

set enableResultsFile to true --         (true/false)
set enableResultsByDialog to false --      (true/false)
set enableNotifications to false --      (true/false)

tell application "System Events" to set parent_name to name of current application

tell application "Finder"
   set script_path to path to me
   set Script_Title to name of file script_path as text
end tell

set SE_Logging to (parent_name = "Script Editor")

if enableResultsFile then
   set Result_DocName to "COP_Profile_Measurements.txt"
else
   set Result_DocName to "Not Enabled"
end if

set ResultMethod to my InitializeLoqqing(Result_DocName, Script_Title)

loq_Results2(0, false, ("Started from: " & parent_name))
loq_Results2(0, false, ("Action: Profile CaptureOne Applescript Commands"))

set minCOPversion to "11.0.1"
validateCOP(minCOPversion)
set {COPDocName, COPDocKind_s, COPDocRef} to validateCOPdoc({"catalog", "session"})
validateCOPcollections2()

set options_display_string to "Debug Level: " & debugLogLevel
set options_display_string to options_display_string & return & "Highest Debug Level in Result File: " & ResultsFileMaxDebug
set options_display_string to options_display_string & return & "Enable Results in Text Edit: " & enableResultsFile
set options_display_string to options_display_string & return & "Display Dialog on Image Not Found: " & enableResultsByDialog
set options_display_string to options_display_string & return & "Enable Results in Notifications: " & enableNotifications
set options_display_string to options_display_string & return & "Results: " & ResultMethod

tell application "System Events" to set frontmost of process parent_name to true

try
   set dialog_result to display dialog options_display_string with title Script_Title
on error errmess
   set everyVariantList to {}
   set newVariantList to {}
   set startingSelectionList to {}
   my loqqed_Error_Halt("User Cancelled the Script")
end try
loq_Results2(1, false, (return & "Options:" & return & options_display_string & return))

set progress description to "Setting Up"
tell application "Capture One 11" to set everyVariantList to every variant -- P#9
set countEveryVariant to get count of everyVariantList

if countEveryVariant ≤ 100 then my loqqed_Error_Halt("The collection is too small (1)")

## Estimate the Group A Profile Duration

set countSelectTrials to 10
if (get countSelectTrials) > countEveryVariant then my loqqed_Error_Halt("The collection is too small (2)")

set variantCounter to 0
set variantSelectedList to {}
tell application "Capture One 11"
   repeat with variantCounter from 1 to countSelectTrials -- make a list of the selected variants which will be deselected for the initial estimate
      set thisVariantSelected to selected of variant variantCounter
      if thisVariantSelected then set the end of variantSelectedList to variant variantCounter
   end repeat
end tell

set variantTrialList to items 1 thru countSelectTrials of everyVariantList
set Mark1 to GetTick_Now()
tell application "Capture One 11" to deselect COPDocRef variants variantTrialList --P#21
set Mark2 to GetTick_Now()
set initP21Duration_msPV to MSduration(Mark1, Mark2) / countSelectTrials
log {"Estimated Group A & B Timeouts: " & (roundtoquantum((countEveryVariant * initP21Duration_msPV / 1000), 0.1))}
set estimate1grpA_TimeOut to (1.5 * countEveryVariant * initP21Duration_msPV / 1000) as integer
if estimate1grpA_TimeOut < 120 then set estimate1grpA_TimeOut to 120
copy estimate1grpA_TimeOut to estimate1grpB_Timeout

tell application "Capture One 11" to select COPDocRef variants variantSelectedList -- now restore the initial selection

tell application "Capture One 11" -- record and erase the intial selection
   with timeout of estimate1grpB_Timeout seconds
      set startingSelectionList to selected variants --P#16
   end timeout
end tell
tell application "Capture One 11" to deselect COPDocRef variants (every variant)
set countSelectedInitVariants to count of startingSelectionList

set progress description to "Profiling"

set maxTrialTime to 5
set VariantBatchSize to 308 -- chosen so that 32.5 * BatchSize = 10,000
copy (1.5 * initP21Duration_msPV) to grpA_DurationPVRef
copy (1 * initP21Duration_msPV) to grpB_DurationPVRef
set logMeasTags to true

repeat with selectionIndex in {5, 40, 100, VariantBatchSize}
   if selectionIndex > countEveryVariant then exit repeat
   set newVariantList to getDistVariantList(everyVariantList, selectionIndex)
   set {grpA_DurationPVRef, grpB_DurationPVRef} to my runProfile(newVariantList, selectionIndex, logMeasTags, grpA_DurationPVRef, grpB_DurationPVRef)
   set logMeasTags to false
end repeat

set last_selectionIndex to 1
set selectionIndex to 2 * VariantBatchSize -- selectionIndex = 1* VariantBatchSize is already done
repeat until selectionIndex > countEveryVariant
   set newVariantList to getDistVariantList(everyVariantList, selectionIndex)
   set {grpA_DurationPVRef, grpB_DurationPVRef} to my runProfile(newVariantList, selectionIndex, logMeasTags, grpA_DurationPVRef, grpB_DurationPVRef)
   
   if selectionIndex ≥ 8 * VariantBatchSize then set VariantBatchSize to 2 * VariantBatchSize
   set last_selectionIndex to selectionIndex + 1
   set selectionIndex to selectionIndex + VariantBatchSize
   set logMeasTags to false
end repeat

if last_selectionIndex ≤ 0.95 * countEveryVariant then
   set {grpA_DurationPVRef, grpB_DurationPVRef} to my runProfile(everyVariantList, countEveryVariant, logMeasTags, grpA_DurationPVRef, grpB_DurationPVRef)
end if

tell application "Capture One 11"
   with timeout of estimate1grpA_TimeOut seconds
      set deselectList to selected variants
      tell COPDocRef to deselect COPDocRef variants everyVariantList
      tell COPDocRef to select COPDocRef variants startingSelectionList
   end timeout
end tell

set everyVariantList to {}
set newVariantList to {}
set startingSelectionList to {}




###########################################################################################################################
## Script Specific Handlers

on runProfile(thisVariantList, countSelectedVariants, logMeasTags, grpA_Duration_msPV, grpB_Duration_msPV)
   global debugLogLevel, maxTrialTime, COPDocName, COPDocKind_s, COPDocRef
   global everyTopCollection, namesTopCollections, kindsTopCollections_p, countTopCollections, selectedCollectionRef, selectedCollectionIndex, kindSelectedCollection_s, nameSelectedCollection, selectedCollectionMirroredAtTopLast, selectedCollectionIsUser, bottomUserCollectionIndex, topUserCollectionIndex
   global countEveryVariant
   
   set grpA_DurationEst1 to (grpA_Duration_msPV * countSelectedVariants / 1000)
   set grpB_DurationEst1 to (grpB_Duration_msPV * countSelectedVariants / 1000)
   set grpB_TimeOut to ((1.25 * grpB_DurationEst1) + 60) as integer
   set grpA_TimeOut to ((1.25 * grpA_DurationEst1) + 120) as integer
   if grpA_TimeOut < 120 then set grpA_TimeOut to 120
   if grpB_TimeOut < 120 then set grpB_TimeOut to 120
   
   loq_Results2(0, false, {return & "Variants: " & countEveryVariant & ", Selected Variants: " & countSelectedVariants & ", Predicted Group A Duration: " & roundtoquantum(grpA_DurationEst1, 0.1) & ", Predicted Group B Duration: " & roundtoquantum(grpB_DurationEst1, 0.1)})
   
   set ProgessTag1 to "Selected Variants: " & countSelectedVariants
   set ProgessTag_GrpA to ProgessTag1 & " Duration: " & (grpA_DurationEst1 as integer) & "s"
   set ProgessTag_GrpB to ProgessTag1 & " Duration: " & (grpB_DurationEst1 as integer) & "s"
   set ProgessTag_GrpC to ProgessTag1 & " Duration: <60s"
   
   try
      set thisProfile to "Initial Check"
      if (get countSelectedVariants as integer) ≠ (get count of thisVariantList) then error "Variant count is incorrect. Given Count: " & countSelectedVariants & "  Given List: " & (count of thisVariantList)
      
      ## Profile 20   Group A Timing
      
      set thisProfile to "Profile 20"
      set progress additional description to thisProfile & ": " & ProgessTag_GrpA
      set countTrials to 1
      set Mark1 to GetTick_Now()
      tell application "Capture One 11"
         with timeout of grpA_TimeOut seconds
            select COPDocRef variants thisVariantList
         end timeout
      end tell
      set Mark2 to GetTick_Now()
      set duration to MSduration(Mark1, Mark2)
      set duration_PV to duration / countTrials / countSelectedVariants
      copy duration_PV to grpA_Duration2_msPV
      
      set MeasTag to ""
      if logMeasTags then set MeasTag to "Target: application \"Capture One 11\", Cmd: select COPDocRef variants thisVariantList,  ASevent: select variants"
      loq_Results2(0, false, {"Profile: 20", " Duration (ms): " & roundtoquantum(duration, 1), " Per Selected Variant (ms): " & roundtoquantum(duration / countSelectedVariants, 1.0E-3), "Trials: 1", MeasTag})
      
      set grpA_TimeOut to ((1.25 * duration / 1000) + 120) as integer
      if grpA_TimeOut < 120 then set grpA_TimeOut to 120
      
      ## Profile 1   Group D Timing
      
      set thisProfile to "Profile 1"
      set progress additional description to thisProfile & ": " & ProgessTag1
      set countTrials to 100
      set Mark1 to GetTick_Now()
      tell application "Capture One 11"
         repeat countTrials times
            set countEveryVariant1 to count of every variant
         end repeat
      end tell
      set Mark2 to GetTick_Now()
      set duration to MSduration(Mark1, Mark2)
      
      set MeasTag to ""
      if logMeasTags then set MeasTag to "Target: application \"Capture One 11\", Cmd: get count of every variant,  ASevent: count every variant of current application"
      loq_Results2(0, false, {"Profile: 1", " Duration (ms): " & roundtoquantum(duration / countTrials, 1), " Per Variant (ms): " & roundtoquantum(duration / countTrials / countEveryVariant, 1.0E-3), "Trials: " & countTrials, "Result: " & countEveryVariant1, MeasTag})
      
      ## Profile 2   Group B Timing
      
      set thisProfile to "Profile 2"
      set progress additional description to thisProfile & ": " & ProgessTag_GrpB
      set countTrials to 1
      set Mark1 to GetTick_Now()
      tell application "Capture One 11"
         with timeout of grpB_TimeOut seconds
            set countSelectedVariants2 to count of selected variants
         end timeout
      end tell
      set Mark2 to GetTick_Now()
      set duration to MSduration(Mark1, Mark2)
      set duration_PV to duration / countTrials / countSelectedVariants
      copy duration_PV to grpB_Duration2_msPV
      
      set MeasTag to ""
      if logMeasTags then set MeasTag to "Target: application \"Capture One 11\", Cmd: get count of selected variants,  ASevent: get count every selected variants of current application"
      loq_Results2(0, false, {"Profile: 2", " Duration (ms): " & roundtoquantum(duration / countTrials, 1), " Per Selected Variant (ms): " & roundtoquantum(duration_PV, 1.0E-3), "Trials: " & countTrials, "Result: " & countSelectedVariants2, MeasTag})
      
      set grpB_TimeOut to ((1.25 * duration / 1000) + 120) as integer
      if grpB_TimeOut < 120 then set grpB_TimeOut to 120
      
      ## Profile 6   Group A Timing
      
      set thisProfile to "Profile 6"
      set progress additional description to thisProfile & ": " & ProgessTag_GrpA
      set countTrials to 1
      set Mark1 to GetTick_Now()
      tell application "Capture One 11"
         with timeout of grpA_TimeOut seconds
            set ListIDselected to id of (every variant whose selected is true)
         end timeout
      end tell
      set Mark2 to GetTick_Now()
      set duration to MSduration(Mark1, Mark2)
      set duration_PV to duration / countTrials / countSelectedVariants
      if duration_PV > grpA_Duration2_msPV then copy duration_PV to grpA_Duration2_msPV
      
      set MeasTag to ""
      if logMeasTags then set MeasTag to "Target: application \"Capture One 11\", Cmd: get id of (every variant whose selected is true),  ASevent: get id of every variant whose selected = true"
      loq_Results2(0, false, {"Profile: 6", " Duration (ms): " & roundtoquantum(duration / countTrials, 1), " Per Selected Variant (ms): " & roundtoquantum(duration_PV, 1.0E-3), "Trials: " & countTrials, "Result: " & (count of ListIDselected), MeasTag})
      
      ## Profile 7   Group D Timing
      
      set thisProfile to "Profile 7"
      set progress additional description to thisProfile & ": " & ProgessTag1
      set countTrials to 100
      set Mark1 to GetTick_Now()
      tell application "Capture One 11"
         repeat countTrials times
            set ListIDall to id of every variant
         end repeat
      end tell
      set Mark2 to GetTick_Now()
      set duration to MSduration(Mark1, Mark2)
      
      set MeasTag to ""
      if logMeasTags then set MeasTag to "Target: application \"Capture One 11\", Cmd: get id of every variant,  ASevent: get id of every variant"
      loq_Results2(0, false, {"Profile: 7", " Duration (ms): " & roundtoquantum(duration / countTrials, 1), " Per Variant (ms): " & roundtoquantum(duration / countTrials / countEveryVariant, 1.0E-3), "Trials: " & countTrials, "Result: " & (count of ListIDall), MeasTag})
      
      ## Profile 8   Group A Timing
      
      set thisProfile to "Profile 8"
      set progress additional description to thisProfile & ": " & ProgessTag_GrpA
      set countTrials to 1
      set Mark1 to GetTick_Now()
      tell application "Capture One 11"
         with timeout of grpA_TimeOut seconds
            set ListRefSelected to (every variant whose selected is true)
         end timeout
      end tell
      set Mark2 to GetTick_Now()
      set duration to MSduration(Mark1, Mark2)
      set duration_PV to duration / countTrials / countSelectedVariants
      if duration_PV > grpA_Duration2_msPV then copy duration_PV to grpA_Duration2_msPV
      
      set MeasTag to ""
      if logMeasTags then set MeasTag to "Target: application \"Capture One 11\", Cmd: get (every variant whose selected is true),  ASevent: get every variant whose selected = true"
      loq_Results2(0, false, {"Profile: 8", " Duration (ms): " & roundtoquantum(duration / countTrials, 1), " Per Selected Variant (ms): " & roundtoquantum(duration_PV, 1.0E-3), "Trials: " & countTrials, "Result: " & (count of ListRefSelected), MeasTag})
      
      ## Profile 9   Group E Timing
      
      set thisProfile to "Profile 9"
      set progress additional description to thisProfile & ": " & ProgessTag_GrpC
      set countTrials to 1
      set Mark1 to GetTick_Now()
      tell application "Capture One 11"
         set ListRefAll to every variant
      end tell
      set Mark2 to GetTick_Now()
      set duration to MSduration(Mark1, Mark2)
      
      set MeasTag to ""
      if logMeasTags then set MeasTag to "Target: application \"Capture One 11\", Cmd: get every variant,  ASevent: get every variant"
      loq_Results2(0, false, {"Profile: 9", " Duration (ms): " & roundtoquantum(duration / countTrials, 1), " Per Variant (ms): " & roundtoquantum(duration / countTrials / countEveryVariant, 1.0E-3), "Trials: " & countTrials, "Result: " & (count of ListRefAll), MeasTag})
      
      set referenceTest9 to duration / countTrials / countEveryVariant
      
      ## Profile 10   Group B Timing
      
      set thisProfile to "Profile 10"
      set progress additional description to thisProfile & ": " & ProgessTag_GrpB
      set countTrials to 1
      set Mark1 to GetTick_Now()
      tell application "Capture One 11"
         with timeout of grpB_TimeOut seconds
            set ListSelectedAll to selected of every variant
         end timeout
      end tell
      set Mark2 to GetTick_Now()
      set duration to MSduration(Mark1, Mark2)
      set duration_PV to duration / countTrials / countSelectedVariants
      if (duration_PV > grpB_Duration2_msPV) then copy duration_PV to grpB_Duration2_msPV
      
      set MeasTag to ""
      if logMeasTags then set MeasTag to "Target: application \"Capture One 11\", Cmd: get selected of every variant,  ASevent: get selected of every variant"
      loq_Results2(0, false, {"Profile: 10", " Duration (ms): " & roundtoquantum(duration / countTrials, 1), " Per Selected Variant (ms): " & roundtoquantum(duration_PV, 1.0E-3), "Trials: " & countTrials, "Result: " & (count of ListSelectedAll), MeasTag})
      
      
      
      ## Profile 11   Group F Timing
      
      set thisProfile to "Profile 11"
      set progress additional description to thisProfile & ": " & ProgessTag1
      set countTrials to 1
      set Mark1 to GetTick_Now()
      set selectedCount to 0
      repeat with variantCounter from 1 to countEveryVariant
         if item variantCounter of ListSelectedAll then set selectedCount to selectedCount + 1
      end repeat
      set Mark2 to GetTick_Now()
      set duration to MSduration(Mark1, Mark2)
      
      set MeasTag to ""
      if logMeasTags then set MeasTag to "Target: Applescript, Cmd: if item variantCounter of ListSelectedAll then set selectedCount to selectedCount + 1,  ASevent: N/A"
      loq_Results2(0, false, {"Profile: 11", " Duration (ms): " & roundtoquantum(duration / countTrials, 1), " Per Variant (ms): " & roundtoquantum(duration / countTrials / countEveryVariant, 1.0E-3), "Trials: " & countTrials, "Result: " & (count of ListSelectedAll), MeasTag})
      
      ## Profile 12   Group F Timing
      ## fixed the incorrect value for IDtrials, 4X too small 2018/06/01
      
      set thisProfile to "Profile 12"
      set progress additional description to thisProfile & ": " & ProgessTag_GrpC
      set countTrials to 10
      set firstID to (first item of ListIDall)
      set lastID to (last item of ListIDall)
      set Mark1 to GetTick_Now()
      tell application "Capture One 11"
         repeat countTrials times
            set variant1 to first variant whose id is firstID
            set variant2 to first variant whose id is lastID
         end repeat
      end tell
      set Mark2 to GetTick_Now()
      set IDtrials to countTrials * 2
      set duration to MSduration(Mark1, Mark2)
      
      set MeasTag to ""
      if logMeasTags then set MeasTag to "Target: application \"Capture One 11\", Cmd: set variant1 to first variant whose id is firstID;set variant2 to ... ,  ASevent: get variant 1 whose id = 'E4A52A26..."
      loq_Results2(0, false, {"Profile: 12", " Duration (ms): " & roundtoquantum(duration / countTrials, 1), " Per Variant (ms): " & roundtoquantum(duration / IDtrials, 1.0E-3), "Trials: " & countTrials, MeasTag})
      
      
      ## Profile 13   Group F Timing
      ## fixed the incorrect value for IDtrials, 4X too small 2018/06/01
      
      set thisProfile to "Profile 13"
      set progress additional description to thisProfile & ": " & ProgessTag_GrpC
      set countTrials to 10
      set Mark1 to GetTick_Now()
      tell application "Capture One 11"
         repeat countTrials times
            set variant1 to variant 1
            set variant2 to variant countEveryVariant
         end repeat
      end tell
      set Mark2 to GetTick_Now()
      set IDtrials to countTrials * 2
      set duration to MSduration(Mark1, Mark2)
      
      set MeasTag to ""
      if logMeasTags then set MeasTag to "Target: application \"Capture One 11\", Cmd: set variant1 to variant 1, set variant2 to variant 2 ,  ASevent: get variant 1; get variant 16249"
      loq_Results2(0, false, {"Profile: 13", " Duration (ms): " & roundtoquantum(duration / countTrials, 1), " Per Variant (ms): " & roundtoquantum(duration / IDtrials, 1.0E-3), "Trials: " & countTrials, MeasTag})
      
      ## Profile 14   Group F Timing
      
      set thisProfile to "Profile 14"
      set progress additional description to thisProfile & ": " & ProgessTag_GrpC
      set countTrials to 100
      set variantCounter to 0
      set selectedCount to 0
      set Mark1 to GetTick_Now()
      tell application "Capture One 11"
         repeat with thisVariant in ListRefAll
            set variantCounter to variantCounter + 1
            if selected of thisVariant then set selectedCount to selectedCount + 1
            if variantCounter ≥ countTrials then exit repeat
         end repeat
      end tell
      set Mark2 to GetTick_Now()
      set duration to MSduration(Mark1, Mark2)
      
      set MeasTag to ""
      if logMeasTags then set MeasTag to "Target: application \"Capture One 11\", Cmd: if selected of thisVariant then set selectedCount to selectedCount + 1,  ASevent: get selected of variant 1 of ..."
      loq_Results2(0, false, {"Profile: 14", " Duration (ms): " & roundtoquantum(duration / countTrials, 1), " Per Variant (ms): " & roundtoquantum(duration / countTrials, 1.0E-3), "Trials: " & countTrials, MeasTag})
      
      set referenceTest14 to duration / countTrials
      
      ## Profile 15   Group D Timing
      
      set thisProfile to "Profile 15"
      set progress additional description to thisProfile & ": " & ProgessTag1
      set countTrials to 1
      set Mark1 to GetTick_Now()
      tell application "Capture One 11" to set ListRatededAll to rating of every variant
      set Mark2 to GetTick_Now()
      set duration to MSduration(Mark1, Mark2)
      
      set MeasTag to ""
      if logMeasTags then set MeasTag to "Target: application \"Capture One 11\", Cmd: get rating of every variant,  ASevent: get rating of every variant"
      loq_Results2(0, false, {"Profile: 15", " Duration (ms): " & roundtoquantum(duration / countTrials, 1), " Per Variant (ms): " & roundtoquantum(duration / countTrials / countEveryVariant, 1.0E-3), "Trials: " & countTrials, "Result: " & (count of ListRatededAll), MeasTag})
      
      ## Profile 16   Group B Timing
      
      set thisProfile to "Profile 16"
      set progress additional description to thisProfile & ": " & ProgessTag_GrpB
      set countTrials to 1
      set Mark1 to GetTick_Now()
      tell application "Capture One 11"
         with timeout of grpB_TimeOut seconds
            set ListRefSelected2 to selected variants
         end timeout
      end tell
      set Mark2 to GetTick_Now()
      set duration to MSduration(Mark1, Mark2)
      set duration_PV to duration / countTrials / countSelectedVariants
      if (duration_PV > grpB_Duration2_msPV) then copy duration_PV to grpB_Duration2_msPV
      
      set MeasTag to ""
      if logMeasTags then set MeasTag to "Target: application \"Capture One 11\", Cmd: get selected variants,  ASevent: get selected variants"
      loq_Results2(0, false, {"Profile: 16", " Duration (ms): " & roundtoquantum(duration / countTrials, 1), " Per Selected Variant (ms): " & roundtoquantum(duration_PV, 1.0E-3), "Trials: " & countTrials, "Result: " & (count of ListRefSelected2), MeasTag})
      
      ## Profile 22   First part    Group F Timing
      
      if countSelectedVariants > 350 then
         set hasProfile22 to true
         
         set thisProfile to "Profile 22"
         set progress additional description to thisProfile & ": " & ProgessTag_GrpA
         set countTrialsP22 to 10
         set Mark1 to GetTick_Now()
         tell application "Capture One 11" to deselect COPDocRef variants (variants 1 thru countTrialsP22)
         set Mark2 to GetTick_Now()
         set durationP22 to MSduration(Mark1, Mark2)
         set durationP22_PV to durationP22 / countTrialsP22
         
      else
         set hasProfile22 to false
         
      end if
      
      
      ## Profile 21   Group A Timing
      
      set thisProfile to "Profile 21"
      set progress additional description to thisProfile & ": " & ProgessTag_GrpA
      set countTrials to 1
      set Mark1 to GetTick_Now()
      tell application "Capture One 11"
         with timeout of grpA_TimeOut seconds
            deselect COPDocRef variants thisVariantList
         end timeout
      end tell
      set Mark2 to GetTick_Now()
      set duration to MSduration(Mark1, Mark2)
      set duration_PV to duration / countTrials / countSelectedVariants
      if duration_PV > grpA_Duration2_msPV then copy duration_PV to grpA_Duration2_msPV
      
      set MeasTag to ""
      if logMeasTags then set MeasTag to "Target: application \"Capture One 11\", Cmd: deselect COPDocRef variants thisVariantList,  ASevent: deselect document xxxx variants {variant 1 ..."
      loq_Results2(0, false, {"Profile: 21", " Duration (ms): " & roundtoquantum(duration / countTrials, 1), " Per Selected Variant (ms): " & roundtoquantum(duration_PV, 1.0E-3), "Trials: " & countTrials, MeasTag})
      
      ## Profile 22 Second Part
      
      if hasProfile22 then
         set MeasTag to ""
         if logMeasTags then set MeasTag to "Target: application \"Capture One 11\", Cmd: deselect COPDocRef variants thisVariantList,  ASevent: deselect document xxxx variants {variant 1 ..."
         loq_Results2(0, false, {"Profile: 22", " Duration (ms): " & roundtoquantum(durationP22 / countTrialsP22, 1), " Per Variant (ms): " & roundtoquantum(durationP22_PV, 1.0E-3), "Trials: " & countTrialsP22, MeasTag})
      else
         if logMeasTags then set MeasTag to "Target: application \"Capture One 11\", Cmd: deselect COPDocRef variants thisVariantList,  ASevent: deselect document xxxx variants {variant 1 ..."
         loq_Results2(0, false, {"Profile: 22", " Duration (ms): " & "-------", " Per Variant (ms): " & "-------", "Trials: " & "-------", MeasTag})
      end if
      
      ## Profile 23   Group D Timing
      ## The setup is Group A timing
      
      set thisProfile to "Profile 23"
      set progress additional description to thisProfile & ": " & ProgessTag_GrpA
      set countTrials to 1
      tell application "Capture One 11"
         with timeout of grpA_TimeOut seconds
            select COPDocRef variants thisVariantList
         end timeout
      end tell
      set Mark1 to GetTick_Now()
      tell application "Capture One 11" to deselect COPDocRef variants (every variant)
      set Mark2 to GetTick_Now()
      set duration to MSduration(Mark1, Mark2)
      set duration_PV to duration / countTrials / countEveryVariant
      
      set MeasTag to ""
      if logMeasTags then set MeasTag to "Target: application \"Capture One 11\", Cmd: deselect COPDocRef variants  (every variant),  ASevent: deselect document xxxx variants every variant"
      loq_Results2(0, false, {"Profile: 23", " Duration (ms): " & roundtoquantum(duration / countTrials, 1), " Per Variant (ms): " & roundtoquantum(duration_PV, 1.0E-3), "Trials: " & countTrials, MeasTag})
      
      #### Final Results
      
      loq_Results2(0, false, "Reference Metric (T14/T9): " & roundtoquantum((referenceTest14 / referenceTest9), 0.1))
      
      
   on error errmess
      set thisVariantList to {}
      set ListIDselected to {} --  #6
      set ListIDall to {} -- #7
      set ListRefSelected to {} --  #8
      set ListRefAll to {} -- #9
      set ListSelectedAll to {} --#10
      set ListRatededAll to {} --  #15
      set ListRefSelected2 to {} -- #16
      
      loqqed_Error_Halt("Failed in " & thisProfile & ": " & errmess)
   end try
   
   set thisVariantList to {}
   set ListIDselected to {} --  #6
   set ListIDall to {} -- #7
   set ListRefSelected to {} --  #8
   set ListRefAll to {} -- #9
   set ListSelectedAll to {} --#10
   set ListRatededAll to {} --  #15
   set ListRefSelected2 to {} -- #16
   
   
   return {grpA_Duration2_msPV, grpB_Duration2_msPV}
   
   ------------  Deprecated measurements
   if false then
      ## Profile 3   Group D Timing  ##Deprecated##
      set Mark1 to GetTick_Now()
      tell application "Capture One 11" to tell COPDocRef to tell selectedCollectionRef
         repeat countTrials times
            set countEveryVariant2 to count of every variant
         end repeat
      end tell
      set Mark2 to GetTick_Now()
      set duration to MSduration(Mark1, Mark2)
      
      loq_Results2(0, false, {"#3", " " & roundtoquantum(duration / countTrials / countEveryVariant2, 1.0E-3) & "ms/var", " " & roundtoquantum(duration / countTrials, 1) & "ms", " " & countTrials & "X", " " & countEveryVariant2 & " variants", "tell application 'Capture One 11' to tell COPDocRef to tell selectedCollectionRef", "count of every variant", "count every variant of collection 1 of document 'Incoming'"})
      
      ## Profile 4   Group A Timing  ##Deprecated##
      set Mark1 to GetTick_Now()
      tell application "Capture One 11" to tell COPDocRef to tell selectedCollectionRef
         with timeout of grpA_TimeOut seconds
            set countSelectedVariants3 to count of (every variant whose selected is true)
         end timeout
      end tell
      set Mark2 to GetTick_Now()
      set duration to MSduration(Mark1, Mark2)
      loq_Results2(0, false, {"#4", " " & roundtoquantum(duration / countEveryVariant, 1.0E-3) & "ms/var", " " & roundtoquantum(duration, 1) & "ms", "1X", " " & countSelectedVariants3 & " selected variants", "tell application 'Capture One 11' to tell COPDocRef to tell selectedCollectionRef", "count of (every variant whose selected is true)", "count every variant of collection 1 of document 'Incoming' whose selected = true"})
      
      ## Profile 5   Group D Timing  ##Deprecated##
      set Mark1 to GetTick_Now()
      tell application "Capture One 11" to tell COPDocRef
         repeat countTrials times
            set countEveryVariant4 to count of every variant
         end repeat
      end tell
      set Mark2 to GetTick_Now()
      set duration to MSduration(Mark1, Mark2)
      
      loq_Results2(0, false, {"#5", " " & roundtoquantum(duration / countTrials / countEveryVariant, 1.0E-3) & "ms/var", " " & roundtoquantum(duration / countTrials, 1) & "ms", " " & countTrials & "X", " " & countEveryVariant4 & " variants", "tell application 'Capture One 11' to tell COPDocRef", "count of every variant", "'count every variant of document 'Incoming'"})
      
      ## Profile 8   Group A Timing  ##Deprecated##
      if false then
         set Mark1 to GetTick_Now()
         tell application "Capture One 11"
            with timeout of grpA_TimeOut seconds
               set ListRefSelected to (every variant whose selected is true)
            end timeout
         end tell
         set Mark2 to GetTick_Now()
         set duration to MSduration(Mark1, Mark2)
         loq_Results2(0, false, {"#8", " " & roundtoquantum(duration / countEveryVariant, 1.0E-3) & "ms/var", " " & roundtoquantum(duration, 1) & "ms", "1X", " " & (count of ListRefSelected) & " selected variants", "tell application 'Capture One 11'", "(every variant whose selected is true)", "get every variant whose selected = true"})
      end if
      
   end if
   
end runProfile

on getDistVariantList(theVariantList, desiredCount)
   set countVariants to count of theVariantList
   if countVariants = 0 then return {}
   if desiredCount = 0 then return {}
   if countVariants ≤ desiredCount then return theVariantList
   if countVariants = 1 then return theVariantList -- for desiredCount and countVariants must both be 1
   set theMiddleIndex to (round (countVariants / 2) rounding down) -- know that countVariants must be >1
   if desiredCount = 1 then return {(item theMiddleIndex of theVariantList)}
   if desiredCount = 2 then return {(item theMiddleIndex of theVariantList), (item (1 + theMiddleIndex) of theVariantList)} -- know that countVariants must be >2
   if desiredCount = 3 then return {(item (theMiddleIndex - 1) of theVariantList), (item theMiddleIndex of theVariantList), (item (theMiddleIndex + 1) of theVariantList)} -- know that countVariants must be >3
   
   set remainingVariantsGap to round ((countVariants - desiredCount) / 2) rounding up
   set firstThird2 to round (desiredCount / 3) rounding down
   set lastThird1 to countVariants - firstThird2 + 1
   set remainingVariants to desiredCount - (countVariants - lastThird1 + 1) - firstThird2
   set middleThird1 to firstThird2 + remainingVariantsGap
   set middleThird2 to middleThird1 - 1 + remainingVariants
   log {"Selected " & desiredCount & " Variants: 1-" & firstThird2 & "," & middleThird1 & "-" & middleThird2 & "," & lastThird1 & "-" & countVariants}
   return (items 1 thru firstThird2 of theVariantList) & (items middleThird1 thru middleThird2 of theVariantList) & (items lastThird1 thru countVariants of theVariantList)
end getDistVariantList


###########################################################################################################################
## Capture One General Handlers

on validateCOP(minCOPversionstr)
   global debugLogLevel
   tell application "System Events"
      set COPProcList to every process whose name contains "Capture One" and background only is false
      if debugLogLevel ≥ 2 then
         set COPProcNameList to name of every process whose name contains "Capture One" and background only is false
         my loq_Results2(2, false, ("COP Processes:" & COPProcNameList))
      end if
   end tell
   if (count of COPProcList) = 0 then my loqqed_Error_Halt("COP is not running")
   if (count of COPProcList) ≠ 1 then my loqqed_Error_Halt("Unexpected: >1 COP instances")
   set theAppRef to item 1 of COPProcList
   tell application "System Events" to set theAppName to ((get name of theAppRef) as text)
   tell application "System Events" to set copDetailedVersion to get version of my application theAppName
   
   tell application "Capture One 11" to set copVersion to (get app version)
   
   if debugLogLevel ≥ 2 then
      --properties of application "Capture One 11"
      tell application "System Events"
         my loq_Results2(2, false, ("All Processes: " & (get my joinListToString((get name of every process whose background only is false), ", "))))
      end tell
      loq_Results2(2, false, ("theAppName: " & theAppName))
      loq_Results2(2, false, ("COP Version: " & copVersion))
      loq_Results2(2, false, ("COP Detailed Version: " & copDetailedVersion))
   end if
   
   if the theAppName ≠ "Capture One 11" then
      display notification "Wrong COP Application"
      my loqqed_Error_Halt("Found COP Application " & theAppName & " The only supported COP application is Capture One 11")
   end if
   
   set numCOPversion to (splitStringToList((word -1 of copVersion), "."))
   set minCOPversion to (splitStringToList(minCOPversionstr, "."))
   
   set digit_mult to 1000000
   set Version_digit to 0
   repeat with dig_ctr from 1 to count of numCOPversion
      set digit_mult to digit_mult / 100
      set Version_digit to Version_digit + (get item dig_ctr of numCOPversion as integer) * digit_mult
   end repeat
   
   set digit_mult to 1000000
   set min_digit to 0
   repeat with dig_ctr from 1 to count of minCOPversion
      set digit_mult to digit_mult / 100
      set min_digit to min_digit + (get item dig_ctr of minCOPversion as integer) * digit_mult
   end repeat
   
   if Version_digit < min_digit then
      display notification "COP Version is too low"
      my loqqed_Error_Halt("This COP Version is " & (word -1 of copVersion) & " - the minimum supported COP version is " & minCOPversionstr)
   end if
   
   tell application "System Events" to set frontmost of process theAppName to true
   loq_Results2(0, false, ("Using Capture One " & copDetailedVersion))
end validateCOP

on validateCOPdoc(COP_kind_list)
   global debugLogLevel
   tell application "Capture One 11"
      set {current_doc_name, current_doc_kind_p} to (get {name, kind} of current document)
      set current_doc_ref_list to (get every document whose name is current_doc_name and kind is current_doc_kind_p)
      set number_of_hits to count of current_doc_ref_list
   end tell
   set current_doc_kind_s to convertKind(current_doc_kind_p)
   loq_Results2(2, false, ("Is: " & current_doc_kind_s & "   was: " & (get current_doc_kind_p as text)))
   loq_Results2(2, false, ("Found Documents: " & number_of_hits))
   
   if COP_kind_list does not contain current_doc_kind_s then loq_Results2(0, false, (current_doc_name & " is a " & current_doc_kind_s & " -- unsupported type of document"))
   
   if number_of_hits = 0 then
      loqqed_Error_Halt("Could not find find " & current_doc_kind_s & current_doc_name)
   else if number_of_hits > 1 then
      loqqed_Error_Halt("Found more than one " & current_doc_kind_s & " with the name " & current_doc_name)
   else
      tell application "Capture One 11" to set current_doc_ref to item 1 of current_doc_ref_list
   end if
   
   loq_Results2(0, false, ("Capture One document: " & current_doc_kind_s & " " & current_doc_name))
   return {current_doc_name, current_doc_kind_s, current_doc_ref}
end validateCOPdoc

on validateCOPcollections2()
   global debugLogLevel, COPDocName, COPDocKind_s, everyTopCollection, namesTopCollections, kindsTopCollections_p, countTopCollections, selectedCollectionRef, selectedCollectionIndex, kindSelectedCollection_s, nameSelectedCollection, selectedCollectionMirroredAtTopLast, selectedCollectionIsUser, bottomUserCollectionIndex, topUserCollectionIndex
   -- selectedCollectionMirroredAtTopLast replaces selectedCollectionAtTopEnd
   -- bottomUserCollectionIndex, topUserCollectionIndex replaces indexInCatalog
   
   tell application "Capture One 11" to tell document COPDocName
      try
         set selectedCollectionRef to get current collection
         set {nameSelectedCollection, kindSelectedCollection_p} to {name, kind} of selectedCollectionRef
      on error
         loqqed_Error_Halt("There is no collection selected in " & current_doc_kind_s & current_doc_name)
      end try
      set everyTopCollection to get every collection
      set {namesTopCollections, kindsTopCollections_p} to {name, kind} of every collection
   end tell
   set kindSelectedCollection_s to convertKind(kindSelectedCollection_p)
   set countTopCollections to count of namesTopCollections
   
   repeat with collectionCounter from 1 to countTopCollections
      if (nameSelectedCollection = item collectionCounter of namesTopCollections) and (kindSelectedCollection_s = convertKind(item collectionCounter of kindsTopCollections_p)) then
         set selectedCollectionIndex to collectionCounter
         exit repeat
      end if
   end repeat
   
   if COPDocKind_s = "catalog" then
      repeat with collectionCounter from countTopCollections to 1 by -1
         if ("in Catalog" = item collectionCounter of namesTopCollections) and ("smart album" = convertKind(item collectionCounter of kindsTopCollections_p)) then
            set topUserCollectionIndex to collectionCounter - 1
            exit repeat
         end if
      end repeat
      repeat with collectionCounter from 1 to countTopCollections
         if ("Trash" = item collectionCounter of namesTopCollections) and ("smart album" = convertKind(item collectionCounter of kindsTopCollections_p)) then
            set bottomUserCollectionIndex to collectionCounter + 1
            exit repeat
         end if
      end repeat
      set selectedCollectionMirroredAtTopLast to (selectedCollectionIndex = countTopCollections) and ({"catalog folder", "favorite"} does not contain convertKind(last item of kindsTopCollections_p))
      set selectedCollectionIsUser to ({"project", "album", "group", "smart album"} contains kindSelectedCollection_s)
   else if COPDocKind_s = "session" then
      repeat with collectionCounter from countTopCollections to 1 by -1
         if ("favorite" ≠ convertKind(item collectionCounter of kindsTopCollections_p)) then
            set topUserCollectionIndex to collectionCounter
            exit repeat
         end if
      end repeat
      repeat with collectionCounter from 1 to countTopCollections
         if ("Trash" = item collectionCounter of namesTopCollections) and ("favorite" = convertKind(item collectionCounter of kindsTopCollections_p)) then
            set bottomUserCollectionIndex to collectionCounter + 1
            exit repeat
         end if
      end repeat
      set selectedCollectionMirroredAtTopLast to false
      set selectedCollectionIsUser to ({"project", "album", "group", "smart album"} contains kindSelectedCollection_s)
   end if
   
   tell application "Capture One 11"
      set countAllVariants to count of every variant
      set countAllImages to count of every image
   end tell
   
   loq_Results2(0, false, ("Current collection: " & kindSelectedCollection_s & " " & nameSelectedCollection & " containing " & countAllImages & " Images  and  " & countAllVariants & " Variants"))
end validateCOPcollections2

on convertKind(kind_p)
   global debugLogLevel
   
   set kind_s to kind_p as text
   if (get text 1 of kind_s) ≠ "«" then
      return kind_s
   else
      set code_start to (get length of kind_s) - 4
      set kind_code to get (text code_start thru (code_start + 3) of kind_s)
      
      if kind_code = "CCpj" then
         set kind_res to "project"
      else if kind_code = "CCgp" then
         set kind_res to "group"
      else if kind_code = "CCal" then
         set kind_res to "album"
      else if kind_code = "CCsm" then
         set kind_res to "smart album"
      else if kind_code = "CCfv" then
         set kind_res to "favorite"
      else if kind_code = "CCff" then
         set kind_res to "catalog folder"
      else if kind_code = "COct" then
         set kind_res to "catalog"
      else if kind_code = "COsd" then
         set kind_res to "session"
      else
         loqqed_Error_Halt("Unexpected Kind string: " & kind_s)
      end if
   end if
   return kind_res
end convertKind

###########################################################################################################################
## General Handlers

on InitializeLoqqing(DocName_Ext, sourceTitle)
   global debugLogLevel, Script_Title, Result_Doc_ref, SE_Logging, enableResultsFile, enableResultsByDialog, DialogTextList
   
   tell current application to set date_string to (current date) as text
   set LogMethods to {}
   
   if enableResultsFile then
      set target_folder_name to "ScriptReports"
      set target_folder_p to ((POSIX path of (get path to desktop as text)) & target_folder_name)
      set target_folder_a to (POSIX file target_folder_p) as string
      set Result_Doc_Path_p to target_folder_p & "/" & DocName_Ext
      set Result_Doc_Path_a to (POSIX file Result_Doc_Path_p) as string
      
      tell application "System Events" to if not (exists (alias (target_folder_a))) then ¬
         tell application "Finder" to make new folder at desktop with properties {name:target_folder_name}
      
      tell application "System Events" to if not (exists (alias (Result_Doc_Path_a))) then
         set First_line to ("Created " & date_string & return)
         do shell script "echo " & First_line & " > " & "\"" & Result_Doc_Path_p & "\""
         if (debugLogLevel ≥ 1) and SE_Logging then log Result_Doc_Path_p & First_line
      end if
      
      tell application "TextEdit" to activate
      tell application "TextEdit" to set Result_Doc_ref to open Result_Doc_Path_a as alias
      set LogMethods to LogMethods & DocName_Ext
   end if
   
   if enableResultsByDialog then
      set DialogTextList to {}
      set LogMethods to LogMethods & "Display Dialog"
   end if
   
   loq_Results2(0, false, (sourceTitle & " results on " & date_string))
   return joinListToString(LogMethods, ", ")
end InitializeLoqqing

on loq_Results2(thisLogDebugLevel, MakeFront, logText)
   global Result_Doc_ref, debugLogLevel, SE_Logging, parent_name, ResultsFileMaxDebug, enableResultsFile, enableResultsByDialog, DialogTextList
   if thisLogDebugLevel > debugLogLevel then return
   
   set logText_class to ((get class of logText) as text)
   if logText_class ≠ "text" then
      try
         if logText_class = "list" then
            set new_logText to joinListToString(logText, ", ")
         else
            set new_logText to logText as text
         end if
         set logText to new_logText
         set logText_class to "text"
      on error errmess
         set logText to errmess
         set logText_class to "text"
      end try
   end if
   
   if ((thisLogDebugLevel ≤ ResultsFileMaxDebug) or not SE_Logging) then
      if enableResultsFile then
         tell application "TextEdit"
            set numPara to count paragraphs of the text of Result_Doc_ref
            set paragraph (numPara + 1) of the text of Result_Doc_ref to ((logText as text) & return)
         end tell
         tell application "System Events" to if MakeFront then set frontmost of process "TextEdit" to true
      end if
      if enableResultsByDialog then
         set DialogTextList to DialogTextList & logText
         if MakeFront then
            tell application "System Events" to set frontmost of process parent_name to true
            display dialog joinListToString(DialogTextList, return)
         end if
      end if
   end if
   
   if SE_Logging then log (logText as text)
   
end loq_Results2

on loqqed_Error_Halt(error_text)
   global debugLogLevel, Script_Title
   tell current application to set date_string to (current date) as text
   loq_Results2(0, true, ("Script \"" & Script_Title & "\" has exited at " & date_string & return & "Reason: " & error_text & return & return & "Halted"))
   display notification error_text
   error error_text
end loqqed_Error_Halt

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

to joinListToString(theList, theDelim)
   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
   on error
      set AppleScript's text item delimiters to astid
   end try
   set AppleScript's text item delimiters to astid
   return theString
end joinListToString

on getIndexOf(theItem, theList) -- credits Emmanuel Levy
   set astid to AppleScript's text item delimiters
   set AppleScript's text item delimiters to return
   set theList to return & theList & return
   set AppleScript's text item delimiters to astid
   try
      -1 + (count (paragraphs of (text 1 thru (offset of (return & theItem & return) in theList) of theList)))
   on error
      0
   end try
end getIndexOf

on roundtoquantum(thisValue, quantum)
   set timePerVariant to (round (thisValue / quantum) rounding to nearest) * quantum
end roundtoquantum

on calculateLog(TheInput)
   set InputType to (class of TheInput) as text
   if InputType = "list" then
      if (count of TheInput) = 0 then
         error "Input is the empty list!!"
      else
         set TheNumber to (item 1 of TheInput) as real
         if (count of TheInput) > 1 then
            set logBasis to item 2 of TheInput
         else
            set logBasis to "10"
         end if
      end if
   else
      set TheNumber to TheInput as real
      set logBasis to "10"
   end if
   if TheNumber = (0 as real) then error "Attempted log of 0!!"
   set TheLog to (do shell script ("echo 'l(" & (TheNumber as string) & ")' | bc -l")) as real
   if (logBasis = "e") then
      -- Do nothing
   else if (logBasis = "10") or (logBasis = (10 as integer)) then
      set TheLog to TheLog / 2.302585092994
   else if (logBasis = "2") or (logBasis = (2 as integer)) then
      set TheLog to TheLog / 0.69314718056
   else
      set logBasis to logBasis as real
      if (logBasis = (0 as real)) then
         error "attempt to use a log basis of 0!!"
      else
         set TheLogConversion to (do shell script ("echo 'l(" & (logBasis as string) & ")' | bc -l")) as real
         set TheLog to TheLog / TheLogConversion
      end if
   end if
   return TheLog
end calculateLog

on MSduration(firstTicks, lastTicks)
   return (round (10000 * (lastTicks - firstTicks)) rounding to nearest) / 10
end MSduration


on GetTick_Now()
   script GetTick
      use framework "Foundation" --> for more precise timing calculations
      on Now()
         return (current application's NSDate's timeIntervalSinceReferenceDate) as real
      end Now
   end script
   
   return GetTick's Now()
end GetTick_Now
Eric Nepean
 
Posts: 655
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