OK, here’s a few samples of what I’m talking about. Of course they’d be formatted for clippings with placeholders. Each is based on one of the ASObjC clippings provided.
This format makes a lot of sense to me. It’s easy to implement and use in as script.
-- ASObjC Replace Considering Case
use framework "Foundation"
set textToSearch to "The quick Red Fox jumped over the brown fox's back"
set textToSearch to ReplaceConderingCase(textToSearch, "fox", "dog")
-- ASObjC handler
on ReplaceConderingCase(textToSearch, stringToFind, replacementString)
-- classes, constants, and enums used
set NSCaseInsensitiveSearch to a reference to 1
set NSString to a reference to current application's NSString
-- ASObjC commands
set textToSearch to NSString's stringWithString:textToSearch
set textToSearch to (textToSearch's stringByReplacingOccurrencesOfString:stringToFind withString:replacementString options:NSCaseInsensitiveSearch range:{0, textToSearch's |length|()}) as text
return textToSearch
end ReplaceConderingCase
-- ASObjC Replace ignoring Case
use framework "Foundation"
set textToSearch to "The quick Red Fox jumped over the brown fox's back"
set textToSearch to ReplaceIgnoringCase(textToSearch, "fox", "dog")
-- ASObjC handler
on ReplaceIgnoringCase(textToSearch, stringToFind, replacementString)
-- classes, constants, and enums used
set NSCaseInsensitiveSearch to a reference to 1
set NSString to a reference to current application's NSString
-- ASObjC commands
set aString to NSString's stringWithString:textToSearch
set sourceString to (aString's stringByReplacingOccurrencesOfString:stringToFind withString:replacementString options:NSCaseInsensitiveSearch range:{0, aString's |length|()}) as text
return aString
end ReplaceIgnoringCase
-- ASObjC - Contents of a folder
use framework "Foundation"
use scripting additions
set fileORURL to choose folder with prompt "Select a folder"
set contentsList to FolderContents(fileORURL)
set entireContentsList to FolderEntireContents(fileORURL)
--ASObjc hander (accepts alias/returns list of URLs)
on FolderContents(fileORURL)
set NSDirectoryEnumerationSkipsHiddenFiles to a reference to 4
set NSFileManager to a reference to current application's NSFileManager
set {theURLs, theError} to NSFileManager's defaultManager()'s contentsOfDirectoryAtURL:fileORURL includingPropertiesForKeys:{} options:(NSDirectoryEnumerationSkipsHiddenFiles) |error|:(reference)
if theURLs is equal to missing value then error (theError's localizedDescription() as text)
set allPosixPaths to (theURLs's valueForKey:"path") as list
return allPosixPaths
end FolderContents
--ASObjc hander (accepts alias/returns list of URLs)
on FolderEntireContents(fileORURL)
set NSFileManager to a reference to current application's NSFileManager
set NSDirectoryEnumerationSkipsHiddenFiles to a reference to 4
set NSDirectoryEnumerationSkipsPackageDescendants to a reference to 2
set theURLs to (NSFileManager's defaultManager()'s enumeratorAtURL:fileORURL includingPropertiesForKeys:{} options:(NSDirectoryEnumerationSkipsPackageDescendants + (get NSDirectoryEnumerationSkipsHiddenFiles)) errorHandler:(missing value))'s allObjects()
set allPosixPaths to (theURLs's valueForKey:"path") as list
end FolderEntireContents
-- ASObjC Make Unique List
use framework "Foundation"
set aList to {"The", "Quick", "Red", "Fox", "The", "Red", "Fox", "is", "Quick"}
set uniqueList to RemoveDuplicatesFromList(aList)
-- ASObjC handler
on RemoveDuplicatesFromList(aList)
-- classes, constants, and enums used
set NSOrderedSet to a reference to current application's NSOrderedSet
-- ASObjC command
set aList to (NSOrderedSet's orderedSetWithArray:aList)'s array() as list
return aList
end RemoveDuplicatesFromList
-- ASObjC is option down
use framework "Foundation"
use framework "AppKit"
set OptionKeyDown to IsOptionKeyDown()
--ASObjc hander (accepts alias/returns boolean)
on IsOptionKeyDown()
-- classes, constants, and enums used
set NSAlternateKeyMask to a reference to 524288
set NSEvent to a reference to current application's NSEvent
-- ASObjC command
set theResult to (((NSEvent's modifierFlags()) div (get NSAlternateKeyMask)) mod 2) = 1
return theResult
end IsOptionKeyDown