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

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

Script for managing Stacks

コメント

1件のコメント

  • Eric Valk
    Part 2.

    Copy and paste this code at the end of the code of part 1.

    ##########################
    ## Capture One General Handlers Version 2019/03/11

    on validateCOP5(minCOPversionstr, maxCOPversionstr)
    ## Copyright 2019 Eric Valk, Ottawa, Canada Creative Commons License CC BY-SA No Warranty.
    ## General purpose initialisation handler for scripts using Capture One Pro
    ## Extract and check basic information about the Capture One application

    global debugLogEnable
    local COPProcList, theAppRef, numCOPversion, minCOPversion, maxCOPversion
    local digit_mult, Version_digit, min_digit, max_digit, copVersionStr
    local theAppName, copVersion

    tell application "System Events"
    if debugLogEnable then
    my loqThis(2, false, ("COP Processes:" & (get my joinlisttostring((get name of every process whose name begins with "Capture One" and background only is false), ", "))))
    my loqThis(3, false, ("All Processes: " & (get my joinlisttostring((get name of every process whose background only is false), ", "))))
    end if
    set COPProcList to every process whose name begins with "Capture One" and background only is false
    if (count of COPProcList) = 0 then return {hasErrors:true, errorText:(get my loqqed_Error_Halt5("COP is not running"))}
    if (count of COPProcList) ≠ 1 then return {hasErrors:true, errorText:(get my loqqed_Error_Halt5("Unexpected: >1 COP instances"))}
    set theAppRef to item 1 of COPProcList
    set theAppName to ((get name of theAppRef) as text)
    set copDetailedVersion to get version of my application theAppName
    end tell

    tell application "Capture One 12" to set copVersionStr to (get app version)
    set copVersion to (word -1 of copVersionStr)

    if debugLogEnable then
    my loqThis(2, false, ("theAppName: " & theAppName))
    my loqThis(1, false, copVersionStr)
    my loqThis(2, false, ("Capture One full Version " & copDetailedVersion))
    end if
    tell my compareVersion(copVersion, minCOPversionstr, maxCOPversionstr) to set {minVersionPass, maxVersionPass} to {its minVersionPass, its maxVersionPass}
    if not minVersionPass then return {hasErrors:true, errorText:(get my loqqed_Error_Halt5(("This Script does not support Capture One " & copDetailedVersion & " - supported versions are from " & minCOPversionstr & " to " & maxCOPversionstr)))}
    if not maxVersionPass then my loqThis(0, true, ("Caution: Capture One " & copDetailedVersion & " has not been verified yet"))
    return {hasErrors:false, theAppName:theAppName, copVersion:copVersion}
    end validateCOP5

    on validateCOPdoc5(theDocRef, validDocKindList)
    ## Copyright 2019 Eric Valk, Ottawa, Canada Creative Commons License CC BY-SA No Warranty.
    ## General purpose initialisation handler for scripts using Capture One Pro
    ## Extract and check basic information about a document

    global debugLogEnable
    local COPDocKind_s, COPDocKind_p, COPDocName

    if "text" = (get class of theDocRef as text) and (0 = (get count of theDocRef)) then tell application "Capture One 12" to set theDocRef to get current document

    try
    tell application "Capture One 12" to set {COPDocName, COPDocKind_p} to get {name, kind} of theDocRef
    on error errorText number errorNumber
    return {hasErrors:true, errorText:(get my loqqed_Error_Halt5("The Script could not retrieve Capture One document info. Error " & errorNumber & ": "" & errorText & """))}
    end try
    set COPDocKind_s to convertKindList(COPDocKind_p)

    if validDocKindList does not contain COPDocKind_s then return {hasErrors:true, errorText:(get my loqqed_Error_Halt5((COPDocName & " is a " & COPDocKind_s & " -- not supported by this script")))}
    return {hasErrors:false, COPDocName:COPDocName, COPDocKind_s:COPDocKind_s}
    end validateCOPdoc5

    on validateCOPcollections5(theDocRef)
    ## Copyright 2019 Eric Valk, Ottawa, Canada Creative Commons License CC BY-SA No Warranty.
    ## General purpose initialisation handler for scripts using Capture One Pro
    ## Extract basic information regarding the current collection, and the top level collections
    global debugLogEnable
    local namesTopCollections, kindsTopCollections_s, countTopCollections, selectedCollectionRef, selectedCollectionIndex, kindSelectedCollection_s, nameSelectedCollection

    tell application "Capture One 12" to set {COPDocName, COPDocKind_p} to get {name, kind} of theDocRef
    set COPDocKind_s to convertKindList(COPDocKind_p)

    tell application "Capture One 12" to tell theDocRef
    set selectedCollectionRef to get current collection
    if (missing value = selectedCollectionRef) then
    try
    set current collection to collection "All Images"
    on error
    set current collection to last collection
    end try
    set selectedCollectionRef to get current collection
    end if
    tell selectedCollectionRef to set {nameSelectedCollection, kindSelectedCollection_s} to {name, my convertKindList(kind)}
    set {namesTopCollections, kindsTopCollections_s} to {every collection's name, my convertKindList(every collection's kind)}
    end tell
    set countTopCollections to count of namesTopCollections

    repeat with collectionCounter from 1 to countTopCollections
    if (nameSelectedCollection = item collectionCounter of namesTopCollections) and ¬
    (kindSelectedCollection_s = item collectionCounter of kindsTopCollections_s) then
    set selectedCollectionIndex to collectionCounter
    exit repeat
    end if
    end repeat

    local selectedCollectionMirroredAtTopLast, bottomUserCollectionIndex, topUserCollectionIndex, countFavoriteCollections, namesFavoriteCollections

    if COPDocKind_s = "catalog" then
    repeat with collectionCounter from countTopCollections to 1 by -1
    if ("in Catalog" = item collectionCounter of namesTopCollections) and ¬
    ("smart album" = item collectionCounter of kindsTopCollections_s) 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" = item collectionCounter of kindsTopCollections_s) then
    set bottomUserCollectionIndex to collectionCounter + 1
    exit repeat
    end if
    end repeat

    set selectedCollectionMirroredAtTopLast to ¬
    (selectedCollectionIndex = countTopCollections) and ¬
    ({"catalog folder", "favorite"} does not contain last item of kindsTopCollections_s)

    set {countFavoriteCollections, namesFavoriteCollections} to {missing value, missing value}

    else if COPDocKind_s = "session" then
    repeat with collectionCounter from countTopCollections to 1 by -1
    if ("favorite" ≠ item collectionCounter of kindsTopCollections_s) 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" = item collectionCounter of kindsTopCollections_s) then
    set bottomUserCollectionIndex to collectionCounter + 1
    exit repeat
    end if
    end repeat

    set countFavoriteCollections to countTopCollections - topUserCollectionIndex
    if 0 = countFavoriteCollections then
    set namesFavoriteCollections to {}
    else
    set namesFavoriteCollections to (get items (topUserCollectionIndex + 1) thru countTopCollections of namesTopCollections)
    end if

    set selectedCollectionMirroredAtTopLast to false
    end if

    local selectedCollectionIsUser, namesTopUserCollections, kindsTopUserCollections_s, countTopUserCollections
    set selectedCollectionIsUser to ¬
    (selectedCollectionMirroredAtTopLast or ¬
    ((selectedCollectionIndex ≥ bottomUserCollectionIndex) and (selectedCollectionIndex ≤ topUserCollectionIndex)))

    if topUserCollectionIndex < bottomUserCollectionIndex then
    set {topUserCollectionIndex, bottomUserCollectionIndex} to {missing value, missing value}
    set {namesTopUserCollections, kindsTopUserCollections_s, countTopUserCollections} to {{}, {}, 0}
    else
    set {namesTopUserCollections, kindsTopUserCollections_s} to {(get items bottomUserCollectionIndex thru topUserCollectionIndex of namesTopCollections), (get items bottomUserCollectionIndex thru topUserCollectionIndex of kindsTopCollections_s)}
    set countTopUserCollections to count of namesTopUserCollections
    end if

    return {hasErrors:false, namesTopUserCollections:namesTopUserCollections, kindsTopUserCollections_s:kindsTopUserCollections_s, countTopUserCollections:countTopUserCollections, selectedCollectionRef:selectedCollectionRef, selectedCollectionIndex:selectedCollectionIndex, kindSelectedCollection_s:kindSelectedCollection_s, nameSelectedCollection:nameSelectedCollection, selectedCollectionMirroredAtTopLast:selectedCollectionMirroredAtTopLast, selectedCollectionIsUser:selectedCollectionIsUser, bottomUserCollectionIndex:bottomUserCollectionIndex, topUserCollectionIndex:topUserCollectionIndex, countFavoriteCollections:countFavoriteCollections, namesFavoriteCollections:namesFavoriteCollections}

    end validateCOPcollections5

    on convertKindList(kind_list)
    ## Copyright 2019 Eric Valk, Ottawa, Canada Creative Commons License CC BY-SA No Warranty.
    ## General Purpose Handler for scripts using Capture One Pro
    ## Capture One returns the chevron form of the "kind" property when AppleScript is run as an Application
    ## Unless care is taken to avoid text conversion of this property, this bug breaks script decisions based on "kind"
    ## This script converts text strings with the chevron form to strings with the expected text form
    ## The input may be a single string, a single enum, a list of strings or a list of enums
    ## The code is not compact but runs very fast, between 60us and 210us per item

    local kind_s_list, input_is_list, theItem, kind_s1, fail_flag, code_start, kind_list, Kind_s_item, kind_code, kind_type

    set kind_s_list to {}
    set input_is_list to ("list" = (get (class of kind_list) as text))
    if input_is_list then
    if ("text" = (get (class of item 1 of kind_list) as text)) and ¬
    ("«" ≠ (get text 1 of item 1 of kind_list)) then return kind_list -- quick pass through if first item is OK
    repeat with theItem in kind_list
    tell application "Capture One 12" to set the end of kind_s_list to (get theItem as text)
    end repeat
    if ("«" ≠ (get text 1 of item 1 of kind_s_list)) then return kind_s_list
    else
    if ("text" = (get (class of kind_list) as text)) and ¬
    ("«" ≠ (get text 1 of kind_list)) then return kind_list -- quick pass through if first item is OK
    tell application "Capture One 12" to set kind_s1 to (get kind_list as text)
    if "«" ≠ (get text 1 of kind_s1) then return kind_s1 -- quick pass through if input is OK
    set kind_s_list to {kind_s1}
    end if

    set fail_flag to false
    set code_start to -5

    set kind_list to {}
    repeat with Kind_s_item in kind_s_list
    if ("«" ≠ (get text 1 of Kind_s_item)) or (16 > (count of Kind_s_item)) then ¬
    error (get my loqqed_Error_Halt5("convertKindList received an unexpected Kind string: " & Kind_s_item))

    set kind_code to get (text code_start thru (code_start + 3) of Kind_s_item)
    set kind_type to get (text code_start thru (code_start + 1) of Kind_s_item)

    if kind_type = "CC" then ## Collection Kinds
    if kind_code = "CCpj" then
    set the end of kind_list to "project"
    else if kind_code = "CCgp" then
    set the end of kind_list to "group"
    else if kind_code = "CCal" then
    set the end of kind_list to "album"
    else if kind_code = "CCsm" then
    set the end of kind_list to "smart album"
    else if kind_code = "CCfv" then
    set the end of kind_list to "favorite"
    else if kind_code = "CCff" then
    set the end of kind_list to "catalog folder"
    else
    set fail_flag to true
    end if

    else if kind_type = "CL" then ## Layer Kinds
    if kind_code = "CLbg" then
    set the end of kind_list to "background"
    else if kind_code = "CLnm" then
    set the end of kind_list to "adjustment"
    else if kind_code = "CLcl" then
    set the end of kind_list to "clone"
    else if kind_code = "CLhl" then
    set the end of kind_list to "heal"
    else
    set fail_flag to true
    end if

    else if kind_type = "CR" then ## Watermark Kinds
    if kind_code = "CRWn" then
    set the end of kind_list to "none"
    else if kind_code = "CRWt" then
    set the end of kind_list to "textual"
    else if kind_code = "CRWi" then
    set the end of kind_list to "imagery"
    else
    set fail_flag to true
    end if

    else if kind_type = "CO" then ## Document Kinds
    if kind_code = "COct" then
    set the end of kind_list to "catalog"
    else if kind_code = "COsd" then
    set the end of kind_list to "session"
    else
    set fail_flag to true
    end if
    else
    set fail_flag to true
    end if

    if fail_flag then ¬
    error (get my loqqed_Error_Halt5("convertKindList received an unexpected Kind string: " & Kind_s_item))

    end repeat

    if input_is_list then
    return kind_list
    else
    return item 1 of kind_list
    end if

    end convertKindList


    ## my joinListToString

    ## Uncomment these next lines if to use these handlers as a Script Library file (".scptd")

    (*
    use AppleScript version "2.5"
    use scripting additions
    use U : script "Utilities_1215"

    if false then false
    *)

    #########################
    ## Logging Handlers Version 2019/02/23

    on setupLoqqing5()
    ## Copyright 2019 Eric Valk, Ottawa, Canada Creative Commons License CC BY-SA No Warranty.
    ## Handler to setup the variables used by the loqqing system at the start of the script

    global debugLogEnable, Loqqing, loqResultDocRef, loqResultMethod, loqDialogTextList
    ## loqResultDocRef is kept separate from Loqqing to allow easy listing of Loqqing

    ## Default values are entered
    set {loqResultDocRef, loqResultMethod} to {false, "not Initialized"}
    set Loqqing to {stateResultDoc:false, gateResultsFile:false, enableResultsFile:false, initResultDoc:false, ResultsFileMaxDebug:0, debugLogLevel:0}
    set Loqqing to Loqqing & {stateResultsByClipboard:true, gateResultsByClipboard:true, enableResultsByClipboard:true}
    set Loqqing to Loqqing & {stateResultsByDialog:false, gateResultsDialog:false, enableResultsByDialog:false, maxDialogPercent:50, maxDialogLines:25, maxDialogChar:1000}
    set Loqqing to Loqqing & {stateResultsByNotification:false, gateResultsNotification:false, enableResultsByNotifications:false, enableNotifications:true, notificationsMaxDebug:0}
    set Loqqing to Loqqing & {stateResultsByLoq:true, gateParentLoqqing:true, enableResultsByLoq:true, initLoqqing:false, gateLoqqing:true}

    end setupLoqqing5

    on InitializeLoqqing5(DocName_Ext, sourceTitle)
    ## Copyright 2019 Eric Valk, Ottawa, Canada Creative Commons License CC BY-SA No Warranty.
    ## Handler to initialize logging of results
    ## Do use loq_Results() until the end of the handler and initialising is completed
    ## Doesn't set loqResultMethod, this is set by caller of this handler

    global parent_name, Script_Title, Loqqing, gateScriptProgress, loqDialogTextList, loqResultDocRef

    local LogMethods, LogHeader, date_string
    tell current application to set date_string to (current date) as text
    set LogMethods to {}
    set LogHeader to (sourceTitle & " results on " & date_string)

    local targetFileWasCreated, TextEditlist, createdLine
    if Loqqing's gateResultsFile and Loqqing's enableResultsFile then
    set end of LogMethods to DocName_Ext
    if not Loqqing's initResultDoc then
    set targetFileWasCreated to false
    set Loqqing's stateResultDoc to false
    set Loqqing's initResultDoc to true

    ## If TextEdit is already open and has the document open then add the headerline
    tell application "System Events" to set TextEditlist to get background only of every application process whose name is "TextEdit"
    if (0 < (count of TextEditlist)) and not item 1 of TextEditlist then
    if (DocName_Ext is in (get name of documents of application "TextEdit")) then
    tell application "TextEdit" to tell document DocName_Ext
    set loqResultDocRef to it
    tell its text to set paragraph (1 + (count paragraphs)) to return & LogHeader & return
    set Loqqing's stateResultDoc to true
    end tell
    end if
    end if
    end if

    local targetFolderParent_a, targetFolderParent_p, targetFolderName, targetFolder_a, targetFolder_p, ResultDocPath_a, ResultDocPath_p, newFolderRef, newFileRef
    if not Loqqing's stateResultDoc or (false = loqResultDocRef) then
    -- create the document and the folder if necessary
    -- Do not use finder to test for the file existence because it has a bug that ignores leading 0's
    -- https://www.macscripter.net/viewtopic.php?id=45178
    set targetFolderParent_a to alias (get path to desktop folder as text)
    set targetFolderParent_p to get POSIX path of targetFolderParent_a
    set targetFolderName to "ScriptReports"
    set targetFolder_p to (targetFolderParent_p & targetFolderName)
    set ResultDocPath_p to targetFolder_p & "/" & DocName_Ext

    try
    set ResultDocPath_a to (get alias POSIX file ResultDocPath_p)
    on error
    try
    set targetFolder_a to (get alias POSIX file targetFolder_p) --x1
    on error
    tell application "Finder" to set newFolderRef to make new folder at targetFolderParent_a with properties {name:targetFolderName}
    set targetFolder_a to newFolderRef as alias
    end try
    tell application "Finder" to set newFileRef to make new file at targetFolder_a with properties {name:DocName_Ext}
    set ResultDocPath_a to newFileRef as alias
    set targetFileWasCreated to true
    end try

    set createdLine to ("Created by " & Script_Title & " on " & date_string)
    tell application "TextEdit" -- open the document and add the first line if empty
    activate
    set loqResultDocRef to open ResultDocPath_a
    tell text of loqResultDocRef
    if targetFileWasCreated then
    set paragraph 1 to createdLine & return & return
    else
    if (0 = (count of paragraphs)) then set paragraph 1 to createdLine & return & return
    end if
    end tell
    if 2 ≤ Loqqing's debugLogLevel then tell me to log ResultDocPath_p & ": " & createdLine
    end tell

    set Loqqing's stateResultDoc to true -- prevents initialisation from repeating
    tell application "TextEdit" to tell text of loqResultDocRef to ¬
    set paragraph (1 + (count paragraphs)) to return & LogHeader & return
    end if
    end if
    if Loqqing's gateResultsFile and Loqqing's stateResultDoc and not Loqqing's enableResultsFile then
    set Loqqing's stateResultDoc to false
    tell application "TextEdit" to tell text of loqResultDocRef to ¬
    set paragraph (1 + (count paragraphs)) to return & parent_name & "Results reporting disabled for: " & Script_Title & return
    end if

    local screenWidthO, screenHeightO, screenWidth, screenHeight, fontSize_pts, charactersPerLine, dotsPer_Point, linesPerScreen, borderLines
    if Loqqing's gateResultsDialog and Loqqing's enableResultsByDialog then
    set end of LogMethods to "Dialogs"
    if not Loqqing's stateResultsByDialog then
    set loqDialogTextList to (get LogHeader & return)
    set Loqqing's stateResultsByDialog to true
    end if
    tell application "Finder" to set {screenWidthO, screenHeightO, screenWidth, screenHeight} to bounds of window of desktop
    set fontSize_pts to 12 -- estimated font size for display dialog, including line spacing
    set charactersPerLine to 58 -- estimated characters per line fo display dialog, if there are no "return" characters
    set dotsPer_Point to 1.5 -- similar for 5K 27" iMac and 11" MBA - similar for others - retina independent
    set linesPerScreen to (screenHeight - screenHeightO) / (fontSize_pts * dotsPer_Point)
    set borderLines to 5
    set Loqqing's maxDialogLines to (get ((Loqqing's maxDialogPercent) / 100 * (linesPerScreen - borderLines)) as integer)
    set Loqqing's maxDialogChar to (get ((Loqqing's maxDialogPercent) / 100 * (linesPerScreen - borderLines) * charactersPerLine) as integer)
    if 2 ≤ Loqqing's debugLogLevel then log {"maxDialogPercent", Loqqing's maxDialogPercent, "screenHeight", screenHeight, "linesPerScreen", linesPerScreen, "maxDialogLines", Loqqing's maxDialogLines, "maxDialogChar", Loqqing's maxDialogChar}
    end if
    if Loqqing's gateResultsDialog and Loqqing's stateResultsByDialog and not Loqqing's enableResultsByDialog then
    set Loqqing's stateResultsByDialog to false
    set loqDialogTextList to ""
    end if

    if Loqqing's gateResultsByClipboard and Loqqing's enableResultsByClipboard then
    set end of LogMethods to "Clipboard"
    if not Loqqing's stateResultsByClipboard then
    set the clipboard to LogHeader
    set Loqqing's stateResultsByClipboard to true
    end if
    end if
    if Loqqing's gateResultsByClipboard and Loqqing's stateResultsByClipboard and not Loqqing's enableResultsByClipboard then
    set the clipboard to {}
    set Loqqing's stateResultsByClipboard to false
    end if

    global gateScriptProgress
    if not Loqqing's initLoqqing then
    set Loqqing's initLoqqing to true
    if ("Script Editor" = parent_name) then
    set Loqqing's gateParentLoqqing to true
    set Loqqing's gateLoqqing to true
    set gateScriptProgress to true
    try -- Open the Log History window
    tell application "System Events" to tell application process "Script Editor"
    if (get name of windows) does not contain "log History" then ¬
    click menu item "Log History" of menu "Window" of menu bar 1
    end tell
    end try
    else if ("Script Debugger" = parent_name) then
    set Loqqing's gateParentLoqqing to true
    set Loqqing's gateLoqqing to true
    set gateScriptProgress to true
    ## Avoids compiler errors when Script Debugger is not present
    run script "tell application "Script Debugger" to tell first document to set event log visible to true"
    run script "tell application "Script Debugger" to tell first document to set event log scope bar visible to true"
    else
    set Loqqing's gateParentLoqqing to false
    set Loqqing's gateLoqqing to false
    set gateScriptProgress to false
    end if
    end if

    if Loqqing's gateParentLoqqing and Loqqing's enableResultsByLoq then
    set end of LogMethods to " " & parent_name & " Log"
    if not Loqqing's stateResultsByLoq then
    set Loqqing's stateResultsByLoq to true
    log "Results Logging enabled for: " & Script_Title
    end if
    end if
    if Loqqing's gateParentLoqqing and Loqqing's stateResultsByLoq and not Loqqing's enableResultsByLoq then
    set Loqqing's stateResultsByLoq to false
    log "Results Logging disabled for: " & Script_Title
    end if

    if (Loqqing's gateResultsNotification and Loqqing's enableResultsByNotifications) or Loqqing's enableNotifications then
    set end of LogMethods to "Notifications"
    if not Loqqing's stateResultsByNotification then
    --display notification "Notifications enabled for: " & Script_Title
    set Loqqing's stateResultsByNotification to true
    end if
    else if Loqqing's stateResultsByNotification then
    display notification "Notifications disabled for: " & Script_Title
    set Loqqing's stateResultsByNotification to false
    end if

    set LogMethods_S to my joinlisttostring(LogMethods, ", ")
    if 2 ≤ Loqqing's debugLogLevel then loqThis(2, false, ("Result Reported by " & LogMethods_S))
    return LogMethods_S
    end InitializeLoqqing5

    on loqThis(thisLogDebugLevel, MakeFront, log_Text)
    ## Copyright 2019 Eric Valk, Ottawa, Canada Creative Commons License CC BY-SA No Warranty.
    ## General purpose handler for logging results
    ## log results if the debug level of the message is below the the threshold set by debugLogLevel
    ## log the results by whatever mechanism is ebabled - {Script Editor Log, Text Editor Log, Display Dialog}

    global parent_name, Loqqing, loqDialogTextList, loqResultDocRef
    local log_Text_S

    if thisLogDebugLevel ≤ Loqqing's debugLogLevel then
    set log_Text_S to my joinlisttostring(log_Text, "; ")
    set triggeredDialog to false

    if (thisLogDebugLevel = 0) then -- Critical errors
    if Loqqing's gateLoqqing then log (log_Text_S)
    if Loqqing's enableResultsByClipboard then set the clipboard to ((get the clipboard) & return & (log_Text_S as text))
    if Loqqing's enableResultsFile then ¬
    tell application "TextEdit" to tell text of loqResultDocRef to ¬
    set paragraph (1 + (count paragraphs)) to (log_Text_S & return)
    if Loqqing's enableResultsByDialog then display alert log_Text_S giving up after 10
    (Loqqing's enableResultsByNotifications and (thisLogDebugLevel ≤ 0))
    else if (thisLogDebugLevel ≤ 0) then -- Expected Results
    if Loqqing's enableResultsByLoq then log (log_Text_S)
    if Loqqing's enableResultsByClipboard then set the clipboard to ((get the clipboard) & return & (log_Text_S as text))

    if Loqqing's enableResultsFile then ¬
    tell application "TextEdit" to tell text of loqResultDocRef to ¬
    set paragraph (1 + (count paragraphs)) to (log_Text_S & return)

    if Loqqing's enableResultsByDialog then -- process the dialog last
    set loqDialogTextList to (get loqDialogTextList & return & log_Text_S)
    if MakeFront or (0 ≥ Loqqing's maxDialogLines) or ¬
    (Loqqing's maxDialogLines < (get count of paragraphs of loqDialogTextList)) or ¬
    (Loqqing's maxDialogChar < (get length of loqDialogTextList)) then
    --tell application "System Events" to set frontmost of process parent_name to true
    display dialog loqDialogTextList
    set triggeredDialog to true
    set loqDialogTextList to ""
    end if
    end if

    else -- debugging information
    if Loqqing's gateLoqqing then log (log_Text_S)
    if Loqqing's enableResultsFile and ((thisLogDebugLevel ≤ Loqqing's ResultsFileMaxDebug) or not Loqqing's gateLoqqing) then ¬
    tell application "TextEdit" to tell text of loqResultDocRef to ¬
    set paragraph (1 + (count paragraphs)) to ((log_Text_S as text) & return)
    end if

    if (Loqqing's enableNotifications and (thisLogDebugLevel ≤ Loqqing's notificationsMaxDebug)) or ¬
    (Loqqing's enableResultsByNotifications and (thisLogDebugLevel ≤ 0)) then
    set paraCtr to 0
    set notString to ""
    set lineCnt to 39
    set paramax to 3
    copy (get paramax * lineCnt) to remChar
    repeat with thePara in (get paragraphs of log_Text_S)
    set thisCount to (get count of (get contents of thePara))
    if thisCount > 0 then
    set paraCtr to paraCtr + 1
    if thisCount > remChar then copy remChar to thisCount
    set notString to notString & (get text 1 thru thisCount of thePara)
    set remChar to remChar - lineCnt * (thisCount div lineCnt)
    if (0 < (thisCount mod lineCnt)) then set remChar to remChar - lineCnt
    if (paramax ≤ paraCtr) or (0 ≥ remChar) then exit repeat
    set notString to notString & return
    end if
    end repeat
    display notification notString
    end if

    if (not triggeredDialog) and (MakeFront or (0 = thisLogDebugLevel)) then --
    if Loqqing's gateLoqqing then tell application "System Events" to set frontmost of process parent_name to true
    if Loqqing's enableResultsFile then tell application "System Events" to set frontmost of process "TextEdit" to true
    end if

    else
    set log_Text_S to ""
    end if
    return log_Text_S
    end loqThis

    on loqqed_Error_Halt5(errorText)
    ## Copyright 2019 Eric Valk, Ottawa, Canada Creative Commons License CC BY-SA No Warranty.
    ## General purpose handler for logging during script termination
    global debugLogEnable, Script_Title
    tell current application to set date_string to (current date) as text
    return (get (loqThis(0, true, ("Script "" & Script_Title & "" is exitting at " & date_string))) & (loqThis(0, true, ("Exit Reason: " & errorText & return))))
    end loqqed_Error_Halt5

    #########################
    ## General Utility Handlers Version 2019/01/12

    on compareVersion(testVersion_S, minVersion_S, maxVersion_S)
    ## Copyright 2019 Eric Valk, Ottawa, Canada Creative Commons License CC BY-SA No Warranty.
    ## General purpose handler for comparing versions
    --local digitMult, testVersionNumber, minVersionNumber, maxVersionNumber, testVersion_LS, minVersion_LS, maxVersion_LS, groupsCount, group_ctr
    --local testGroupsCount, minGroupsCount, maxGroupsCount, hasTestGroup, hasMinGroup, hasMaxGroup, testGroupVersion, minGroupVersion, maxGroupVersion
    --local allBoundsPass, lowerBoundPass, upperBoundPass, lowerBoundFail, upperBoundFail

    if (text ≠ (get class of testVersion_S)) or (text ≠ (get class of minVersion_S)) or (text ≠ (get class of maxVersion_S)) then error "Text inputs only"

    set testVersion_LS to (splitstringtolist(removeLeadingTrailingSpaces(testVersion_S), "."))
    set minVersion_LS to (splitstringtolist(removeLeadingTrailingSpaces(minVersion_S), "."))
    set maxVersion_LS to (splitstringtolist(removeLeadingTrailingSpaces(maxVersion_S), "."))

    set testGroupsCount to get count of testVersion_LS
    set minGroupsCount to get count of minVersion_LS
    set maxGroupsCount to get count of maxVersion_LS

    set groupsCount to testGroupsCount
    if groupsCount < minGroupsCount then set groupsCount to minGroupsCount
    if groupsCount < maxGroupsCount then set groupsCount to maxGroupsCount

    set lowerBoundPass to false
    set lowerBoundFail to false
    set upperBoundPass to false
    set upperBoundFail to false

    repeat with group_ctr from 1 to groupsCount

    set hasTestGroup to (get group_ctr ≤ testGroupsCount)
    set hasMinGroup to (get group_ctr ≤ minGroupsCount)
    set hasMaxGroup to (get group_ctr ≤ maxGroupsCount)

    if hasTestGroup then set testGroupVersion to (get (item group_ctr of testVersion_LS) as integer)
    if hasMinGroup then set minGroupVersion to (get (item group_ctr of minVersion_LS) as integer)
    if hasMaxGroup then set maxGroupVersion to (get (item group_ctr of maxVersion_LS) as integer)

    if not (lowerBoundPass or lowerBoundFail) then
    if hasMinGroup and hasTestGroup then
    if testGroupVersion > minGroupVersion then set lowerBoundPass to true
    if testGroupVersion < minGroupVersion then set lowerBoundFail to true
    else if hasMinGroup then -- (and no testGroup) e.g. test 11 , min 11.1
    set lowerBoundFail to true -- not symetric with upper bound behaviour
    else if hasTestGroup then -- (and no minGroup) e.g. test 11.1, min 11 --> OK
    set lowerBoundPass to true
    end if
    end if

    if not (upperBoundPass or upperBoundFail) then
    if hasMaxGroup and hasTestGroup then
    if testGroupVersion < maxGroupVersion then set upperBoundPass to true
    if testGroupVersion > maxGroupVersion then set upperBoundFail to true
    else if hasMaxGroup then -- (and no testGroup) e.g. test 11.1 , max 11.1.2 or test 11 , max 11.1
    set upperBoundPass to true -- not symetric with lower bound behaviour
    else if hasTestGroup then --(and no maxGroup) e.g. test 11.1, max 11 --> pass
    set upperBoundPass to true
    end if
    end if

    end repeat

    return {maxVersionPass:(not upperBoundFail), minVersionPass:(not lowerBoundFail)}
    end compareVersion


    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

    on removeLeadingTrailingSpaces(theListString)
    ## 40% faster than a version which trims the string 1 space at a time
    ## handles both string and list input correctly
    -- local theListString, input_is_list, cleanList, thecount, hasTriggered, indexLow, indexHigh

    set input_is_list to ("list" = (get (class of theListString) as text))
    if not input_is_list then set theListString to {theListString}

    set cleanList to {}
    repeat with theString in theListString
    if ("text" = (get (class of theString) as text)) then
    set thecount to (get count of theString)
    set hasTriggered to false
    repeat with indexLow from 1 to thecount
    if " " ≠ (get text indexLow of theString as text) then
    set hasTriggered to true
    exit repeat
    end if
    end repeat
    if not hasTriggered then
    set theString to ""
    else
    repeat with indexHigh from -1 to (-thecount) by -1
    if " " ≠ (get text indexHigh of theString as text) then exit repeat
    end repeat
    set theString to text indexLow thru indexHigh of theString
    end if
    end if

    set the end of cleanList to theString
    end repeat

    if input_is_list then return cleanList

    return (get contents of theString)
    end removeLeadingTrailingSpaces

    on removeLeadingTrailingSpaces2(theListString, trimLeading, trimTrailing)
    ## 40% faster than a version which trims the string 1 space at a time
    ## handles both string and list input correctly
    local theListString, input_is_list, cleanList, thecount, foundChar, isAllBlanks, indexLow, indexHigh

    set input_is_list to ("list" = (get (class of theListString) as text))
    if not input_is_list then set theListString to {theListString}

    set cleanList to {}
    repeat with theString in theListString
    if ("text" = (get (class of theString) as text)) then
    set {thecount, indexLow, indexHigh, isAllBlanks} to {(get count of theString), 1, -1, false}
    if trimLeading then
    set foundChar to false
    repeat with indexLow from 1 to thecount
    if " " ≠ (get text indexLow of theString as text) then
    set foundChar to true
    exit repeat
    end if
    end repeat
    set isAllBlanks to not foundChar
    end if
    if trimTrailing and not isAllBlanks then
    set foundChar to false
    repeat with indexHigh from -1 to (-thecount) by -1
    if " " ≠ (get text indexHigh of theString as text) then
    set foundChar to true
    exit repeat
    end if
    end repeat
    set isAllBlanks to not foundChar
    end if
    if isAllBlanks then
    set theString to ""
    else
    set theString to text indexLow thru indexHigh of theString
    end if
    end if

    set the end of cleanList to theString
    end repeat

    if input_is_list then return cleanList
    return (get contents of theString)
    end removeLeadingTrailingSpaces2

    on removeTextFromList(theList, theBadChar)
    ## theBadChar may be a string or character, whereupon that string will be removed
    ## theBadChar may be a list of strings or characters, whereupon those strings will be removed

    set theDelim to character id 60000 -- obscure character chosen for the low likelihood of its appearance
    set astid to AppleScript's text item delimiters
    try
    set AppleScript's text item delimiters to theDelim
    set theString to theList as string
    set AppleScript's text item delimiters to theBadChar
    set text_list to every text item of theString
    set AppleScript's text item delimiters to ""
    set cleanText_S to the text_list as string
    set AppleScript's text item delimiters to theDelim
    set theList to text items of cleanText_S
    end try
    set AppleScript's text item delimiters to astid

    return theList
    end removeTextFromList

    on removeItemFromList(theList, theBadItem)
    ## theBadChar may be a string or character, whereupon that string will be removed
    ## theBadChar may be a list of strings or characters, whereupon those strings will be removed
    local theDelim, theString, text_list, cleanText_S, errorText, astid
    set theDelim1 to character id 60000 -- obscure characters chosen for the low likelihood of its appearance
    set theDelim2 to character id 60001
    set astid to AppleScript's text item delimiters
    try
    set AppleScript's text item delimiters to {theDelim2 & theDelim1}
    set theString to theDelim1 & (theList as string) & theDelim2
    set AppleScript's text item delimiters to theDelim1 & theBadItem & theDelim2
    set text_list to every text item of theString
    set AppleScript's text item delimiters to ""
    set cleanText_S to text_list as string
    if 2 < (count of cleanText_S) then
    set cleanText_S to text 2 thru -2 of (text_list as string)
    else
    set cleanText_S to ""
    end if
    set AppleScript's text item delimiters to {theDelim2 & theDelim1}
    set theList to text items of cleanText_S
    end try
    set AppleScript's text item delimiters to astid

    return theList
    end removeItemFromList

    on replaceText(this_text, search_string, replacement_string)
    set astid to AppleScript's text item delimiters
    try
    set AppleScript's text item delimiters to the search_string
    set the item_list to every text item of this_text
    set AppleScript's text item delimiters to the replacement_string
    set this_text to the item_list as string
    end try
    set AppleScript's text item delimiters to astid
    return this_text
    end replaceText
    [/code]
    0

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