text
stringlengths
0
15.7k
source
stringlengths
6
112
end alias for key
lns3.scpt
on remove value for key theKey
lns3.scpt
if class of theKey is not text then error "The 'remove value for key' command requires a string for its direct parameter" to text
lns3.scpt
accessDefaults()'s removeObjectForKey:theKey
lns3.scpt
end remove value for key
lns3.scpt
on assign defaults defaultsRecord
lns3.scpt
if class of defaultsRecord is not record then error "The 'assign defaults' command requires a record as its direct parameter" to record
lns3.scpt
accessDefaults()'s registerDefaults:defaultsRecord
lns3.scpt
error "The 'assign defaults' command failed, with the error: " & errMessage
lns3.scpt
end assign defaults
lns3.scpt
on accessDefaults()
lns3.scpt
if theDefaults is missing value then error "The 'prepare storage' command has not yet been called by this script"
lns3.scpt
return theDefaults
lns3.scpt
end accessDefaults
lns3.scpt
use AppleScript version "2.4" -- macOS 10.10 or later
lns3.scpt
property NSCharacterSet : a reference to current application's NSCharacterSet
lns3.scpt
property NSMutableString : a reference to current application's NSMutableString
lns3.scpt
property NSRegularExpression : a reference to current application's NSRegularExpression
lns3.scpt
property NSLocale : a reference to current application's NSLocale
lns3.scpt
property theSentinal : "ʬߓชი" -- used as a marker to split and join lists
lns3.scpt
on lowercase from theValue using locale localizing : false
lns3.scpt
if class of theValue is text then
lns3.scpt
set theString to NSString's stringWithString:theValue
lns3.scpt
if localizing then
lns3.scpt
return (theString's localizedLowercaseString()) as text
lns3.scpt
return (theString's lowercaseString()) as text
lns3.scpt
else if class of theValue is list then
lns3.scpt
set theList to NSArray's arrayWithArray:theValue
lns3.scpt
return (theList's valueForKey:"localizedLowercaseString") as list
lns3.scpt
return (theList's valueForKey:"lowercaseString") as list
lns3.scpt
error "Value is not a string or list."
lns3.scpt
end lowercase from
lns3.scpt
on uppercase from theValue using locale localizing : false
lns3.scpt
return (theString's localizedUppercaseString()) as text
lns3.scpt
return (theString's uppercaseString()) as text
lns3.scpt
return (theList's valueForKey:"localizedUppercaseString") as list
lns3.scpt
return (theList's valueForKey:"uppercaseString") as list
lns3.scpt
end uppercase from
lns3.scpt
on titlecase from theValue using locale localizing : false
lns3.scpt
return (theString's localizedCapitalizedString()) as text
lns3.scpt
return (theString's capitalizedString()) as text
lns3.scpt
return (theList's valueForKey:"localizedCapitalizedString") as list
lns3.scpt
return (theList's valueForKey:"capitalizedString") as list
lns3.scpt
end titlecase from
lns3.scpt
on split string theString using delimiters splitters
lns3.scpt
set {saveTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, splitters}
lns3.scpt
end split string
lns3.scpt
on join strings theList using delimiter joinerString
lns3.scpt
set {saveTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {joinerString}}
lns3.scpt
set theString to theList as text
lns3.scpt
end join strings
lns3.scpt
on regex search theString search pattern thePattern match case matchCase : false dot matches all dotMatchesAll : false anchors match lines anchorsMatchLines : true Unicode boundaries unicodeBoundaries : false replace template replaceTemplate : (missing value) capture groups captureGroup : 0 using sentinal useSentinal : true
lns3.scpt
set theOpts to (not matchCase) as integer
lns3.scpt
if dotMatchesAll then set theOpts to theOpts + 8
lns3.scpt
if anchorsMatchLines then set theOpts to theOpts + 16
lns3.scpt
if unicodeBoundaries then set theOpts to theOpts + 64
lns3.scpt
set {theRegex, theError} to NSRegularExpression's regularExpressionWithPattern:thePattern options:theOpts |error|:(reference)
lns3.scpt
if theRegex = missing value then error theError's localizedDescription() as text
lns3.scpt
set theString to NSMutableString's stringWithString:theString
lns3.scpt
if replaceTemplate is missing value and class of captureGroup is integer then set replaceTemplate to "$" & captureGroup -- make template of capture group
lns3.scpt
if replaceTemplate is not missing value then
lns3.scpt
if useSentinal then
lns3.scpt
set theReplace to theSentinal & replaceTemplate & theSentinal
lns3.scpt
set matchCount to (theRegex's replaceMatchesInString:theString options:0 range:{0, theString's |length|()} withTemplate:theReplace)
lns3.scpt
if matchCount is 0 then return {} -- no matches, so return
lns3.scpt
theString's insertString:theSentinal atIndex:0
lns3.scpt
theString's appendString:theSentinal
lns3.scpt
set tempRegex to theSentinal & "(?s).*?" & theSentinal
lns3.scpt
theString's replaceOccurrencesOfString:tempRegex withString:theSentinal options:1024 range:{0, theString's |length|()} -- options is NSRegularExpressionSearch
lns3.scpt
set tempList to (theString's componentsSeparatedByString:theSentinal)
lns3.scpt
return (tempList's subarrayWithRange:{1, (tempList's |count|()) - 2}) as list
lns3.scpt
set theMatches to theRegex's matchesInString:theString options:0 range:{0, theString's |length|()}
lns3.scpt
set matchCount to theMatches's |count|()
lns3.scpt
if matchCount = 0 then return {}
lns3.scpt
set theList to NSMutableArray's arrayWithCapacity:matchCount
lns3.scpt
repeat with aMatch in theMatches
lns3.scpt
set oneString to (theRegex's replacementStringForResult:aMatch inString:theString |offset|:0 template:replaceTemplate)
lns3.scpt
if oneString is missing value then
lns3.scpt
(theList's addObject:"")
lns3.scpt
(theList's addObject:oneString)
lns3.scpt
return (theList as list)
lns3.scpt
else if class of captureGroup is list then
lns3.scpt
set subList to (my buildSublistFrom:theString captureGroups:captureGroup fromMatch:aMatch regularExpression:theRegex)
lns3.scpt
(theList's addObject:subList)
lns3.scpt
error "Capture groups value is not an integer or list."
lns3.scpt
end regex search
lns3.scpt
on regex search once theString search pattern thePattern match case matchCase : false dot matches all dotMatchesAll : false anchors match lines anchorsMatchLines : true Unicode boundaries unicodeBoundaries : false replace template replaceTemplate : (missing value) capture groups captureGroup : 0 backwards search fromBack : false
lns3.scpt
set theString to NSString's stringWithString:theString
lns3.scpt
if not fromBack then
lns3.scpt
set theMatch to theRegex's firstMatchInString:theString options:0 range:{0, theString's |length|()}
lns3.scpt
if theMatch is missing value then return missing value
lns3.scpt
return my resultFrom:theString captureGroups:captureGroup fromMatch:theMatch replaceTemplate:replaceTemplate regularExpression:theRegex
lns3.scpt
if theMatches's |count|() = 0 then return missing value
lns3.scpt
set theMatch to theMatches's lastObject()
lns3.scpt
end regex search once
lns3.scpt
on resultFrom:theString captureGroups:captureGroup fromMatch:theMatch replaceTemplate:replaceTemplate regularExpression:theRegex
lns3.scpt
set oneString to (theRegex's replacementStringForResult:theMatch inString:theString |offset|:0 template:replaceTemplate)
lns3.scpt
return oneString as text
lns3.scpt
if class of captureGroup is list then
lns3.scpt
return (my buildSublistFrom:theString captureGroups:captureGroup fromMatch:theMatch regularExpression:theRegex) as list
lns3.scpt