text
stringlengths 0
15.7k
| source
stringlengths 6
112
|
---|---|
set argumentsSynopsis to argumentsSynopsis & space & valuePlaceholder
|
lns3.scpt
|
return {" [--]" & argumentsSynopsis, argumentsSection}
|
lns3.scpt
|
end _formatArguments
|
lns3.scpt
|
to parse command line arguments argv ¬
|
lns3.scpt
|
options optionDefinitions : {} ¬
|
lns3.scpt
|
arguments argumentDefinitions : {} ¬
|
lns3.scpt
|
default options hasDefaultOptions : (true)
|
lns3.scpt
|
set argv to _support's asListParameter(argv, "")
|
lns3.scpt
|
set optionDefinitions to _support's asListParameter(optionDefinitions, "")
|
lns3.scpt
|
set argumentDefinitions to _support's asListParameter(argumentDefinitions, "")
|
lns3.scpt
|
set {asocParametersDict, argumentsList} to _parseOptions(items of argv, optionDefinitions, hasDefaultOptions)
|
lns3.scpt
|
_addDefaultOptions(asocParametersDict, optionDefinitions)
|
lns3.scpt
|
_parseArguments(argumentsList, argumentDefinitions, asocParametersDict)
|
lns3.scpt
|
return asocParametersDict as any -- coerce the dictionary to an AS record and return it
|
lns3.scpt
|
if eNumber = _ArgvUserError then
|
lns3.scpt
|
_error("parse command line arguments", eText, eNumber, eFrom, eTo)
|
lns3.scpt
|
end parse command line arguments
|
lns3.scpt
|
to format command line help name commandName : ("") ¬
|
lns3.scpt
|
summary shortDescription : ("") ¬
|
lns3.scpt
|
synopsis commandSynopses : {} ¬
|
lns3.scpt
|
description longDescription : ("") ¬
|
lns3.scpt
|
terminal styles isStyled : (true) ¬
|
lns3.scpt
|
set commandName to _support's asTextParameter(commandName, "name")
|
lns3.scpt
|
set commandSynopses to _support's asListParameter(commandSynopses, "")
|
lns3.scpt
|
set shortDescription to _support's asTextParameter(shortDescription, "summary")
|
lns3.scpt
|
set longDescription to _support's asTextParameter(longDescription, "documentation")
|
lns3.scpt
|
if _support's asBooleanParameter(isStyled, "terminal styles") then
|
lns3.scpt
|
set vtStyle to {n:VT100(0), b:VT100(1), u:VT100(4)} -- normal, bold, underline
|
lns3.scpt
|
set vtStyle to {n:"", b:"", u:""}
|
lns3.scpt
|
if commandName is "" then -- use the AppleScript shell script's own file name by default
|
lns3.scpt
|
set commandName to item -1 of (split path (_ of (environment variables)))
|
lns3.scpt
|
set commandName to "COMMAND" -- fallback on the offchance the above should fail to get the script's file name
|
lns3.scpt
|
set helpText to vtStyle's b & "NAME" & vtStyle's n & LF2 & Indent1 & commandName
|
lns3.scpt
|
if shortDescription is not "" then
|
lns3.scpt
|
set helpText to helpText & " -- " & shortDescription
|
lns3.scpt
|
set {defaultOptionsSynopsis, optionsSection} to _formatOptions(optionDefinitions, vtStyle, hasDefaultOptions)
|
lns3.scpt
|
set {defaultArgumentsSynopsis, argumentsSection} to _formatArguments(argumentDefinitions, vtStyle)
|
lns3.scpt
|
set helpText to helpText & LF2 & vtStyle's b & "SYNOPSIS" & vtStyle's n
|
lns3.scpt
|
if commandSynopses is {} then
|
lns3.scpt
|
set commandSynopses to {commandName & defaultOptionsSynopsis & defaultArgumentsSynopsis}
|
lns3.scpt
|
repeat with textRef in commandSynopses
|
lns3.scpt
|
set helpText to helpText & LF2 & Indent1 & textRef
|
lns3.scpt
|
_support's throwInvalidParameterType(commandSynopses, "synopsis", list, "list of text")
|
lns3.scpt
|
if optionsSection is not "" then set helpText to helpText & LF2 & optionsSection
|
lns3.scpt
|
if argumentsSection is not "" then set helpText to helpText & LF2 & argumentsSection
|
lns3.scpt
|
if longDescription is not "" then
|
lns3.scpt
|
set helpText to helpText & LF2 & vtStyle's b & "DESCRIPTION" & vtStyle's n & LF2 & longDescription
|
lns3.scpt
|
return helpText & linefeed
|
lns3.scpt
|
_error("format command line help", eText, eNumber, eFrom, eTo)
|
lns3.scpt
|
end format command line help
|
lns3.scpt
|
to current working directory
|
lns3.scpt
|
set asocPath to current application's NSFileManager's defaultManager()'s currentDirectoryPath()
|
lns3.scpt
|
if asocPath is missing value then error "Not available." number -1728
|
lns3.scpt
|
return asocPath as text as POSIX file
|
lns3.scpt
|
_error("current working directory", eText, eNumber, eFrom, eTo)
|
lns3.scpt
|
end current working directory
|
lns3.scpt
|
to environment variables
|
lns3.scpt
|
return (current application's NSProcessInfo's processInfo()'s environment()) as any
|
lns3.scpt
|
end environment variables
|
lns3.scpt
|
to read from standard input with prompt promptText : (">> ") user interaction isInteractive : (false)
|
lns3.scpt
|
set asocStdin to current application's NSFileHandle's fileHandleWithStandardInput()
|
lns3.scpt
|
if isInteractive then
|
lns3.scpt
|
write to standard output promptText without normalized line breaks and automatic line ending
|
lns3.scpt
|
set asocData to asocStdin's availableData()
|
lns3.scpt
|
if asocData's |length|() = 0 then return missing value
|
lns3.scpt
|
set asocData to asocStdin's readDataToEndOfFile()
|
lns3.scpt
|
set asocString to current application's NSString's alloc()'s initWithData:asocData encoding:(current application's NSUTF8StringEncoding)
|
lns3.scpt
|
if asocString is missing value then error "Input is not UTF8-encoded text." number -1700
|
lns3.scpt
|
if asocString's hasSuffix:linefeed then set asocString to asocString's substringToIndex:((asocString's |length|()) - 1)
|
lns3.scpt
|
_error("read from standard input", eText, eNumber, eFrom, eTo)
|
lns3.scpt
|
end read from standard input
|
lns3.scpt
|
to write to standard output theText normalized line breaks useLinefeeds : (true) automatic line ending withLineEnding : (true)
|
lns3.scpt
|
set asocString to _support's asNSMutableString(_support's asTextParameter(theText, ""))
|
lns3.scpt
|
if useLinefeeds then
|
lns3.scpt
|
asocString's replaceOccurrencesOfString:(return & linefeed) ¬
|
lns3.scpt
|
withString:(linefeed) options:0 range:{location:0, |length|:asocString's |length|()}
|
lns3.scpt
|
asocString's replaceOccurrencesOfString:(return) ¬
|
lns3.scpt
|
if withLineEnding and not (asocString's hasSuffix:linefeed) then asocString's appendString:linefeed
|
lns3.scpt
|
set asocStdout to current application's NSFileHandle's fileHandleWithStandardOutput()
|
lns3.scpt
|
asocStdout's writeData:(asocString's dataUsingEncoding:(current application's NSUTF8StringEncoding))
|
lns3.scpt
|
_error("write to standard output", eText, eNumber, eFrom, eTo)
|
lns3.scpt
|
end write to standard output
|
lns3.scpt
|
script SmartString
|
lns3.scpt
|
property parent : AppleScript
|
lns3.scpt
|
property theString : ""
|
lns3.scpt
|
on newString(aString) --> script object factory method
|
lns3.scpt
|
copy me to anObject
|
lns3.scpt
|
anObject's setString(aString)
|
lns3.scpt
|
end newString
|
lns3.scpt
|
on getString() --> string (only reads)
|
lns3.scpt
|
end getString
|
lns3.scpt
|
on setString(aString) --> string
|
lns3.scpt
|
set theString to aString as string
|
lns3.scpt
|
end setString
|
lns3.scpt
|
on setList(aList, seperator) --> string
|
lns3.scpt
|
set theString to convertListToString(aList, seperator)
|
lns3.scpt
|
end setList
|
lns3.scpt
|
on subString(x, y) --> string (only reads)
|
lns3.scpt
|
return text x thru y of theString
|
lns3.scpt
|
end subString
|
lns3.scpt
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.