Script to find images not in any user collection
***Edit*** 2020/07/05 The migrated version of this script likely will not complile because the Applescript symbols for "not equal", "less than" and "greater than" are not supported in the new forum
Here is a script that checks all images to find those who are not in any user collection. I have verified it running from Script Editor and from Capture One.
## Notes
-- Updates based on: COP Find Uncollected Image 3
-- Updated code in main part
-- Not checked. Need to update the Search handler.
-- Applescript to search a COP 11 Catalog for Images not in any Collection
-- Version 1.5 !! NO SUPPORT !! Eric Valk, Ottawa, Canada
-- ***To Initialise
-- Start Script Editor, open a new (blank) file, copy and paste all of this code into the file, compile (hammer symbol) and save.
-- Best if you make "Scripts" folder somewhere in your Documents or Desktop
-- *** 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 first in Notifications, then the Script Editor Log and Text Edit when the search for each variant is completed, and in Display Dialog Window when all searching is completed
-- 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 longer to report
set enableResultsFile to true -- (true/false)
set enableResultsByDialog to false -- (true/false)
set enableNotifications to false -- (true/false)
set ResultsFileMaxDebug to 2 -- 1...6 suggest not more than 2
set notificationUpdateInterval to 60 -- update interval for notification
## ***** 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 maxSearchlevel to 100 -- Reduce if you only want to search top level collections Range 1...100. Verified to 100
set SearchLookbackFolders to 15 -- the number of collections which are saved in the cache. These are the last collections where images were found.
set SearchDiskFileSystem to false -- don't change this as the search will give incorrect results, it will always find the image
set SearchRecentImports to false -- don't change this as the search will give incorrect results, it will always find images from the last import
set SearchRecentCaptures to false -- don't change this as the search will give incorrect results, it will always find images from the last capture
set SearchTrash to false -- don't change this as the search will give incorrect results, it will also find images in the Trash
set ExcludedSubCollectionNames to {""} -- These collections listed will not be searched
set StopSearchAtProject to false -- safe to change (true/false)
set ExcludedTopCollectionNames to {"In Catalog", "Catalog", "All Images"}
if SearchDiskFileSystem then
set ExcludedTopCollectionKinds to {""}
else
set ExcludedTopCollectionKinds to {"catalog folder"}
end if
if not SearchRecentImports then set ExcludedTopCollectionNames to ExcludedTopCollectionNames & "Recent Imports"
if not SearchRecentCaptures then set ExcludedTopCollectionNames to ExcludedTopCollectionNames & "Recent Captures"
if not SearchTrash then set ExcludedTopCollectionNames to ExcludedTopCollectionNames & "Trash"
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_Image_Search.txt"
else
set Result_DocName to "Not Enabled"
end if
set ResultMethod to my InitializeLoqqing(Result_DocName, Script_Title)
loq_Results("Started from: " & parent_name, false, 0)
loq_Results("Action: Find images which are not in any user collection", false, 0)
set minCOPversion to "11.0.1"
validateCOP(minCOPversion)
set {COPDocName, COPDocKind_s, COPDocRef} to validateCOPdoc({"catalog", "session"})
validateCOPcollections()
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 & "Maximum Search Level: " & maxSearchlevel
set options_display_string to options_display_string & return & "Enable Results in Text Edit: " & enableResultsFile
set options_display_string to options_display_string & return & "Enable Results in Dialog: " & 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
set options_display_string to options_display_string & return & "Search Managed Files: " & false
set options_display_string to options_display_string & return & "Search Referenced Files: " & SearchDiskFileSystem
set options_display_string to options_display_string & return & "Search Recent Imports: " & SearchRecentImports
set options_display_string to options_display_string & return & "Search Recent Captures: " & SearchRecentCaptures
set options_display_string to options_display_string & return & "Search All Images: " & false
set options_display_string to options_display_string & return & "Search COP Trash: " & SearchTrash
set options_display_string to options_display_string & return & "Other Excluded Collections: " & ExcludedSubCollectionNames
set options_display_string to options_display_string & return & "Do Not Search below Projects: " & StopSearchAtProject
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
my loqqedErrorHalt("User Cancelled the Script")
end try
loq_Results((return & "Options:" & return & options_display_string & return), false, 1)
tell application "Capture One 11"
tell document COPDocName
set AllImagesCollection to get the collection "All Images"
tell AllImagesCollection
set {All_Images_Name, All_Images_ID} to get the {name, id} of every image
end tell
end tell
end tell
set count_All_Images to get count of All_Images_ID
loq_Results(("In this window " & count_All_Images & " Variants"), false, 3)
if count_All_Images = 0 then
display alert "Catalog is empty, there are no images"
loqqedErrorHalt("No images in catalog")
else
set startTime to get time of (get current date)
tell application "Capture One 11" to set everyCollection to get every collection of document COPDocName
set allResults to {}
set search_executed to false
set last_search_hit to ""
set search_hit_list to {}
set search_level_list to {}
set search_name_list to {}
set search_kind_list to {}
set search_hit_list_len to 0
set last_search_level to 0
set CacheHitRate to 0
set CacheEfficency to 0
if SE_Logging then
set progress total steps to count_All_Images
set progress completed steps to 0
set progress description to "Searching "
else
copy startTime to lastnotificationTime
end if
set hitListSuccess to 0
set hitListAttempts to 0
set hitListFail to 0
repeat with i_Counter from 1 to count_All_Images
set searchedImageID to item i_Counter of All_Images_ID
set searchedImageName to item i_Counter of All_Images_Name
if i_Counter > 1 then set CacheHitRate to (100 * hitListSuccess / (i_Counter - 1)) as integer
if hitListSuccess > 0 then set CacheEfficency to ((10 * hitListAttempts / hitListSuccess) as integer) / 10
if SE_Logging then
set progress completed steps to i_Counter
set progress additional description to ("#" & i_Counter & " Cache: " & CacheHitRate & "% - " & CacheEfficency & "x " & search_hit_list_len)
else
set notificationTime to (get time of (get current date))
if (notificationTime - lastnotificationTime) ≥ notificationUpdateInterval then
display notification "Image " & i_Counter & " of " & count_All_Images & " (Cache: " & CacheHitRate & "% - " & CacheEfficency & "x) " & search_hit_list_len
set lastnotificationTime to notificationTime
end if
end if
loq_Results(("Searching for Image " & i_Counter & ": " & searchedImageID), false, 2)
set isFound to false
## set search_hit_list_len to count of search_hit_list
repeat with c_Counter from 1 to search_hit_list_len
set hitListAttempts to hitListAttempts + 1
set thisSubCollection to item c_Counter of search_hit_list
set thisSubCollection_level to item c_Counter of search_level_list
set subCollName to item c_Counter of search_name_list
set subCollKind_s to item c_Counter of search_kind_list
if false then
tell application "Capture One 11" to tell document COPDocName to tell thisSubCollection
set subCollName to get name as text
set subCollKind_s to my convertKind(kind)
end tell
end if
set isFound to my search_collection(thisSubCollection, thisSubCollection_level, subCollName, subCollKind_s)
if isFound then
loq_Results((searchedImageName & " found in previous location " & subCollKind_s & " " & subCollName), false, 3)
set hitListSuccess to hitListSuccess + 1
else
loq_Results((searchedImageName & " not found in previous location " & subCollKind_s & " " & subCollName), false, 3)
set hitListFail to hitListFail + 1
end if
if isFound then exit repeat
end repeat
if not isFound then
set SearchLevel to 0
set nextSearchLevel to SearchLevel + 1
repeat with c_Counter from 1 to count of everyCollection
set thisTopCollection to item c_Counter of everyCollection
set topCollName to item c_Counter of namesTopCollections
set topCollKind_s to my convertKind(item c_Counter of kindsTopCollections_p)
if (ExcludedTopCollectionNames does not contain topCollName) and (ExcludedTopCollectionKinds does not contain topCollKind_s) then
set search_executed to true
set isFound to my search_collection(thisTopCollection, nextSearchLevel, topCollName, topCollKind_s)
if isFound then
loq_Results((searchedImageName & " found in " & topCollKind_s & " " & topCollName), false, 3)
else
loq_Results((searchedImageName & " not found in " & topCollKind_s & " " & topCollName), false, 3)
end if
if isFound then exit repeat
end if
end repeat
end if
if not search_executed then -- there are no top level collections to search - don't keep searching
loqqedErrorHalt("No Top Level Collections to Search")
end if
if isFound then
set is_on_list to false
repeat with list_hit_ptr from 1 to search_hit_list_len
if last_search_hit = (get item list_hit_ptr of search_hit_list) then
set is_on_list to true
exit repeat
end if
end repeat
if not is_on_list then
set search_hit_list to {last_search_hit} & search_hit_list
set search_level_list to {last_search_level} & search_level_list
set search_name_list to {last_search_name} & search_name_list
set search_kind_list to {last_search_kind_s} & search_kind_list
if SearchLookbackFolders < (get length of search_hit_list) then
set search_hit_list to items 1 thru SearchLookbackFolders of search_hit_list
set search_level_list to items 1 thru SearchLookbackFolders of search_level_list
set search_name_list to items 1 thru SearchLookbackFolders of search_name_list
set search_kind_list to items 1 thru SearchLookbackFolders of search_kind_list
end if
else -- last hit is on the hit list
if list_hit_ptr ≠1 then -- if the last hit is not first on the hit list, then move it to first
set search_hit_list_next to {last_search_hit} & (items 1 thru (list_hit_ptr - 1) of search_hit_list)
set search_level_list_next to {last_search_level} & (items 1 thru (list_hit_ptr - 1) of search_level_list)
set search_name_list_next to {last_search_name} & (items 1 thru (list_hit_ptr - 1) of search_name_list)
set search_kind_list_next to {last_search_kind_s} & (items 1 thru (list_hit_ptr - 1) of search_kind_list)
if list_hit_ptr ≠search_hit_list_len then
set search_hit_list_next to search_hit_list_next & (items (list_hit_ptr + 1) thru search_hit_list_len of search_hit_list)
set search_level_list_next to search_level_list_next & (items (list_hit_ptr + 1) thru search_hit_list_len of search_level_list)
set search_name_list_next to search_name_list_next & (items (list_hit_ptr + 1) thru search_hit_list_len of search_name_list)
set search_kind_list_next to search_kind_list_next & (items (list_hit_ptr + 1) thru search_hit_list_len of search_kind_list)
end if
set search_hit_list to search_hit_list_next
set search_level_list to search_level_list_next
set search_name_list to search_name_list_next
set search_kind_list to search_kind_list_next
end if
end if
set search_hit_list_len to (get length of search_hit_list) -- update the list lenght value is correct after editting the list
if debugLogLevel ≥ 2 then
set notification_text to searchedImageName & " was found in a User Collection"
my loq_Results(notification_text, false, 2)
end if
else
set notification_text to (searchedImageName & " was not found anywhere")
my loq_Results(notification_text, false, 0)
display notification notification_text
end if
end repeat
set stopTime to get time of (get current date)
repeat while stopTime < startTime
set startTime to startTime - 86400 -- the search started on a previous day
end repeat
set elapsedtime to stopTime - startTime
set searchTimePerVariant to ((1000 * elapsedtime / count_All_Images) as integer) / 1000
tell application "System Events" to set frontmost of process "Capture One 11" to true
if enableResultsFile then tell application "System Events" to set frontmost of process "TextEdit" to true
loqqed_exit(return & "This search took " & elapsedtime & " seconds (" & searchTimePerVariant & "s per variant)")
end if
## Execution will never reach this line
--Handlers -------------------
on search_collection(thisCollection, SearchLevel, thisCollName, thisCollKind_s)
-- recursive handler to search a collection and it's subcollections
-- if successful, returns a list of paths each as a text string
global debugLogLevel, SE_Logging, maxSearchlevel, searchedImageID, searchedImageName, COPDocName, StopSearchAtProject, ExcludedSubCollectionNames, selected_collection_index, enableNotifications, last_search_hit, last_search_level, last_search_name, last_search_kind_s
if ExcludedSubCollectionNames contains thisCollName then return false
## if SE_Logging then set progress additional description to thisCollKind & " " & thisCollName
tell application "Capture One 11" to tell document COPDocName to tell thisCollection
set searchImageIDhits to count of (get every image whose id is searchedImageID)
set countSubcollsthisColl to count of every collection
end tell
if debugLogLevel ≥ 5 then
tell application "Capture One 11" to tell document COPDocName to tell thisCollection
set countImages to count of every image
set countVariants to count of every variant
end tell
loq_Results(("In " & thisCollKind_s & " " & thisCollName & " at level " & SearchLevel & " found " & countImages & " images ," & countVariants & " variants ," & countSubcollsthisColl & " collections"), false, 5)
end if
if searchImageIDhits > 0 then
set isFound to true
if enableNotifications then display notification searchedImageName & " found in: " & thisCollKind_s & " '" & thisCollName & "'"
loq_Results(("Found " & searchImageIDhits & " hits in " & thisCollKind_s & " " & thisCollName), false, 4)
if SE_Logging then set progress description to "Found in " & thisCollKind_s & " " & thisCollName
set last_search_hit to thisCollection
set last_search_level to SearchLevel
set last_search_name to thisCollName
set last_search_kind_s to thisCollKind_s
return isFound
else -- isFound is false -- no hits in this collection
set isFound to false
end if
tell application "Capture One 11" to tell document COPDocName to tell thisCollection
set listSubcollsthisColl to every collection
if countSubcollsthisColl > 0 then set {namesSubcollsthisColl, kindsSubcollsthisColl_p} to {name, kind} of every collection
end tell
set nextSearchLevel to SearchLevel + 1
if (nextSearchLevel ≤ maxSearchlevel) and ¬
(not (StopSearchAtProject and thisCollKind_s = "project")) then
loq_Results(("Searching Collections in " & thisCollKind_s & " " & thisCollName & " at level " & SearchLevel & " found " & countSubcollsthisColl & " collections"), false, 5)
repeat with c_Counter from 1 to countSubcollsthisColl
set searchColl to item c_Counter of listSubcollsthisColl
set searchCollName to item c_Counter of namesSubcollsthisColl
set searchCollKind_s to convertKind(get item c_Counter of kindsSubcollsthisColl_p)
if selected_collection_index ≠0 then
## A user sub-collection has been selected
## Check the collection number to trap the error caused by the selected subcollection returning an invalid referencee
try
|| of {searchColl} -- generate an error to capture error text containing the collection reference
on error CO11_errtxt number CO11_errnbr
end try
loq_Results(("***Error Message " & CO11_errtxt & "; number " & CO11_errnbr & " Collection: " & c_Counter & " of " & thisCollKind_s & " " & thisCollName), false, 4)
## extract the collection number from the error text
if CO11_errnbr = -1728 then
set CollNum to (get last word of item 2 of splitStringToList(CO11_errtxt, "of")) as integer
else
loq_Results(("*****" & CO11_errtxt & "; number " & CO11_errnbr), false, 4)
loqqedErrorHalt("Unexpected error when checking collection integrity")
end if
if CollNum ≠c_Counter then
## this is the selected sub collection, and must be accesed as the last top level collection in the document
if selected_collection_index ≠CollNum then
## the collection reference is wrong in some other unexpected way
loq_Results(("*****" & CO11_errtxt & "; number " & CO11_errnbr), false, 4)
loqqedErrorHalt("Unexpected collection index when checking collection integrity: " & CollNum)
end if
## Set the collection reference to the last top level collection
tell application "Capture One 11" to tell document COPDocName to set searchColl to collection CollNum
loq_Results(("Top Level Collection number:" & CollNum & " replaces Sub collection " & c_Counter & " of " & thisCollKind_s & " " & thisCollName), false, 3)
end if
loq_Results(("Verified sub-Collection " & c_Counter & " of " & thisCollKind_s & " " & thisCollName), false, 4)
end if
loq_Results(("Starting search in " & searchCollName & " (" & searchCollKind_s & ") "), false, 4)
set isFound to my search_collection(searchColl, nextSearchLevel, searchCollName, searchCollKind_s) -- the search
loq_Results(("Result of search in " & searchCollName & " (" & searchCollKind_s & ") is: " & isFound), false, 3)
if isFound then return isFound
end repeat
end if
return isFound
end search_collection
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_Results("COP Processes:" & COPProcNameList, false, 2)
end if
end tell
if (count of COPProcList) = 0 then my loqqedErrorHalt("COP is not running")
if (count of COPProcList) ≠1 then my loqqedErrorHalt("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_Results(("All Processes: " & (get my joinListToString((get name of every process whose background only is false), ", "))), false, 2)
end tell
loq_Results(("theAppName: " & theAppName), false, 2)
loq_Results(("COP Version: " & copVersion), false, 2)
loq_Results(("COP Detailed Version: " & copDetailedVersion), false, 2)
end if
if the theAppName ≠"Capture One 11" then
display notification "Wrong COP Application"
my loqqedErrorHalt("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 loqqedErrorHalt("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_Results(("Using Capture One " & copDetailedVersion), false, 0)
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_Results(("Is: " & current_doc_kind_s & " was: " & (get current_doc_kind_p as text)), false, 2)
loq_Results(("Found Documents: " & number_of_hits), false, 2)
if COP_kind_list does not contain current_doc_kind_s then loq_Results(current_doc_name & " is a " & current_doc_kind_s & " -- unsupported type of document", false, 0)
if number_of_hits = 0 then
loqqedErrorHalt("Could not find find " & current_doc_kind_s & current_doc_name)
else if number_of_hits > 1 then
loqqedErrorHalt("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_Results(("Capture One document: " & current_doc_kind_s & " " & current_doc_name), false, 0)
return {current_doc_name, current_doc_kind_s, current_doc_ref}
end validateCOPdoc
on validateCOPcollections()
global debugLogLevel, COPDocName, everyTopCollection, namesTopCollections, kindsTopCollections_p, max_search_coll_index, selected_collection_index
tell application "Capture One 11" to tell document COPDocName
set everyTopCollection to get every collection
set {namesTopCollections, kindsTopCollections_p} to {name, kind} of every collection
set lastCollectionIndex to count of everyTopCollection
set kindOfLastCollection_p to (get kind of collection lastCollectionIndex) as text
set nameOfLastCollection to (get name of collection lastCollectionIndex) as text
set kindOf2ndLastCollection_p to (get kind of collection (lastCollectionIndex - 1)) as text
set nameOf2ndLastCollection to (get name of collection (lastCollectionIndex - 1)) as text
end tell
set kindOfLastCollection_s to convertKind(kindOfLastCollection_p)
set kindOf2ndLastCollection_s to convertKind(kindOf2ndLastCollection_p)
if kindOfLastCollection_s = "catalog folder" then
## last collection definitely is NOT the selected collection
set max_search_coll_index to lastCollectionIndex
set selected_collection_index to 0
else if kindOf2ndLastCollection_s = "catalog folder" then
## last collection definitely IS the selected collection
set max_search_coll_index to lastCollectionIndex - 1
set selected_collection_index to lastCollectionIndex
else
## The last two collections are not catalog folders. Likely there are no catalog folders, all images are stored in the catalog
if nameOfLastCollection = "In Catalog" then
## last collection definitely is NOT the selected collection
set max_search_coll_index to lastCollectionIndex
set selected_collection_index to 0
else if nameOf2ndLastCollection = "In Catalog" then
## last collection definitely IS the selected collection
set max_search_coll_index to lastCollectionIndex - 1
set selected_collection_index to lastCollectionIndex
else
## Undetermined and unexpected collection arrangement
loq_Results(("Unexpected Collection Structure #" & ¬
(lastCollectionIndex - 1) & " " & kindOf2ndLastCollection_p & " " & nameOf2ndLastCollection & ¬
" #" & lastCollectionIndex & " " & kindOfLastCollection_p & " " & nameOfLastCollection), false, 0)
loq_Results(("Unexpected Collection Structure"), false, 0)
loq_Results(("Collection #" & (lastCollectionIndex - 1) & " (" & kindOf2ndLastCollection_p & ") " & kindOf2ndLastCollection_s & " " & nameOf2ndLastCollection), false, 0)
loq_Results(("Collection #" & lastCollectionIndex & " (" & kindOfLastCollection_p & ") " & kindOfLastCollection_s & " " & nameOfLastCollection), false, 0)
set max_search_coll_index to lastCollectionIndex
set selected_collection_index to lastCollectionIndex
end if
end if
end validateCOPcollections
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 (debug ≥ 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_Results((sourceTitle & " results on " & date_string), false, 0)
return joinListToString(LogMethods, ", ")
end InitializeLoqqing
on loq_Results(logText, MakeFront, thisLogDebugLevel)
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_Results
on loqqedErrorHalt(error_text)
global debugLogLevel, Script_Title
cleanGlobals()
loq_Results(("Script "" & Script_Title & "" has exited." & return & "Reason: " & error_text & return & return & "Halted"), true, 0)
display notification error_text
error error_text
end loqqedErrorHalt
on loqqed_exit(exit_text)
global debugLogLevel, Script_Title
cleanGlobals()
loq_Results((exit_text & return & Script_Title & " completed with no errors" & return), true, 0)
end loqqed_exit
on cleanGlobals()
global All_Images_Name, All_Images_ID, everyTopCollection, namesTopCollections, namesTopCollections, kindsTopCollections_p, search_hit_list, search_level_list, earch_name_list, search_kind_list
## Cleanup Memory to avoid Script Editor having a stack overflow error on saving; this data will be dirty on the next run anyway
set All_Images_Name to {}
set All_Images_ID to {}
set everyTopCollection to {}
set namesTopCollections to {}
set kindsTopCollections_p to {}
set search_hit_list to {}
set search_level_list to {}
set search_name_list to {}
set search_kind_list to {}
end cleanGlobals
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 indexof(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 indexof
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
loqqedErrorHalt("Unexpected Kind string: " & kind_s)
end if
end if
return kind_res
end convertKind
Post is closed for comments.
Comments
0 comments