text
stringlengths
0
15.7k
source
stringlengths
6
112
tell application frontApp
lns2.scpt
set msgStr to "CONTROL Key has been mapped to: " & newKeyMap
lns2.scpt
set msgTitleStr to "Remap of Modifier Keys"
lns2.scpt
display dialog msgStr with title msgTitleStr
lns2.scpt
on pauseUntilWin(pWinTitle, pProcessName, pMaxTimeSec)
lns2.scpt
local startTime, elapTime, errMsg
lns2.scpt
set startTime to current application's NSDate's |date|()
lns2.scpt
repeat until window pWinTitle of process pProcessName exists
lns2.scpt
if ((startTime's timeIntervalSinceNow()) > pMaxTimeSec) then
lns2.scpt
set errMsg to "Max Time of " & pMaxTimeSec & " exceeded waiting for:" & LF & ¬
lns2.scpt
"Window: " & pWinTitle & LF & "Process: " & pProcessName
lns2.scpt
log errMsg
lns2.scpt
error errMsg
lns2.scpt
set uiElem to UI elements of window pWinTitle of process pProcessName
lns2.scpt
set elapTime to (-(round ((startTime's timeIntervalSinceNow()) * 100)) / 100.0)
lns2.scpt
return elapTime
lns2.scpt
end pauseUntilWin
lns2.scpt
to time zone info for timezone : ("current") in language localeCode : ("none")
lns2.scpt
set asocTimeZone to _asNSTimeZoneParameter(timezone, "for")
lns2.scpt
set asocLocale to _support's asNSLocaleParameter(localeCode, "in language")
lns2.scpt
set DSTOffset to asocTimeZone's daylightSavingTimeOffset()
lns2.scpt
if DSTOffset mod 1 = 0 then set DSTOffset to DSTOffset as integer
lns2.scpt
to _makeDateFormatter(theFormat, localeCode, timezone)
lns2.scpt
set asocFormatter to current application's NSDateFormatter's alloc()'s init()
lns2.scpt
asocFormatter's setDefaultDate:_epochDate()
lns2.scpt
asocFormatter's setTimeZone:(_asNSTimeZoneParameter(timezone, "time zone"))
lns2.scpt
asocFormatter's setCalendar:_gregorianCalendar()
lns2.scpt
if (count {theFormat} each text) = 1 then -- use custom format string
lns2.scpt
asocFormatter's setDateFormat:(_support's asTextParameter(theFormat, "using"))
lns2.scpt
else -- use predefined date-style and/or time-style constants
lns2.scpt
set formatTypes to _support's asListParameter(theFormat, "")
lns2.scpt
if formatTypes is {canonical date format} then -- return ISO8601 formatter
lns2.scpt
asocFormatter's setDateFormat:_ISO8601Format
lns2.scpt
asocFormatter's setDateStyle:(current application's NSDateFormatterNoStyle)
lns2.scpt
asocFormatter's setTimeStyle:(current application's NSDateFormatterNoStyle)
lns2.scpt
set {isDateSet, isTimeSet} to {false, false}
lns2.scpt
repeat with aRef in formatTypes
lns2.scpt
set {isDate, asocOption} to _dateStyle(aRef's contents, theFormat)
lns2.scpt
if isDate then
lns2.scpt
if isDateSet then _support's throwInvalidParameter(formatTypes, "using", list, "Conflicting date formats.")
lns2.scpt
(asocFormatter's setDateStyle:asocOption)
lns2.scpt
set isDateSet to true
lns2.scpt
if isTimeSet then _support's throwInvalidParameter(formatTypes, "using", list, "Conflicting time formats.")
lns2.scpt
(asocFormatter's setTimeStyle:asocOption)
lns2.scpt
set isTimeSet to true
lns2.scpt
end _makeDateFormatter
lns2.scpt
to format date theDate using theFormat : {canonical date format} for locale localeCode : ("none") time zone timezone : ("current")
lns2.scpt
set theDate to _support's asDateParameter(theDate, "")
lns2.scpt
set asocFormatter to _makeDateFormatter(theFormat, localeCode, timezone)
lns2.scpt
return (asocFormatter's stringFromDate:theDate) as text
lns2.scpt
_error("format date", eText, eNumber, eFrom, eTo)
lns2.scpt
end format date
lns2.scpt
to parse date theText using theFormat : {canonical date format} for locale localeCode : ("none") time zone timezone : ("current") -- note that `time zone` param is ignored when TZ is provided by date text
lns2.scpt
set asocText to current application's NSString's stringWithString:(_support's asTextParameter(theText, ""))
lns2.scpt
set asocDate to asocFormatter's dateFromString:theText
lns2.scpt
if asocDate is missing value then -- parsing failed, so report error
lns2.scpt
set localeIdentifier to asocFormatter's locale()'s localeIdentifier()
lns2.scpt
if localeIdentifier is missing value or (localeIdentifier as text)'s length = 0 then set localeIdentifier to "none"
lns2.scpt
_support's throwInvalidParameter(theText, "", text, "Text is not in the correct format (expected date text in “" & (asocFormatter's dateFormat()) & "” format for “" & localeIdentifier & "” locale).")
lns2.scpt
return asocDate as date -- note that AS dates don't include time zone info, so resulting date object always uses host machine's current time zone, regardless of what time zone the original date text used, adjusting its time appropriately
lns2.scpt
_error("parse date", eText, eNumber, eFrom, eTo)
lns2.scpt
end parse date
lns2.scpt
to join date dateProperties time zone timezone : ("current")
lns2.scpt
set dateRecord to _support's asOptionalRecordParameter(dateProperties, {class:date component record, year:2001, month:1, day:1, hours:0, minutes:0, seconds:0, timezone:missing value}, "") -- uses 1 January 2001, 00:00:00 *local time* as default
lns2.scpt
if dateRecord's timezone is missing value then
lns2.scpt
set timezone to _asNSTimeZoneParameter(timezone, "time zone")
lns2.scpt
set timezone to _asNSTimeZoneParameter(dateRecord's timezone, "time zone")
lns2.scpt
_support's throwInvalidParameter(dateProperties, "", record, "Date component record contains invalid ‘timezone’ property.")
lns2.scpt
set asocDateInfo to current application's NSDateComponents's alloc()'s init()
lns2.scpt
asocDateInfo's setCalendar:_gregorianCalendar()
lns2.scpt
asocDateInfo's setTimeZone:timezone
lns2.scpt
asocDateInfo's setYear:(_support's asWholeNumber(dateRecord's year))
lns2.scpt
set theMonth to dateRecord's month
lns2.scpt
if {theMonth} is in _months then
lns2.scpt
asocDateInfo's setMonth:(theMonth as integer)
lns2.scpt
asocDateInfo's setMonth:(_support's asWholeNumber(theMonth))
lns2.scpt
asocDateInfo's setDay:(_support's asWholeNumber(dateRecord's day))
lns2.scpt
asocDateInfo's setHour:(_support's asWholeNumber(dateRecord's hours))
lns2.scpt
asocDateInfo's setMinute:(_support's asWholeNumber(dateRecord's minutes))
lns2.scpt
asocDateInfo's setSecond:(_support's asWholeNumber(dateRecord's seconds))
lns2.scpt
if not asocDateInfo's isValidDate() then error number -1700
lns2.scpt
return asocDateInfo's |date|() as any
lns2.scpt
_support's throwInvalidParameter(dateProperties, "", record, "Date component record does not represent a valid date.")
lns2.scpt
_error("join date", eText, eNumber, eFrom, eTo)
lns2.scpt
end join date
lns2.scpt
_support's throwCommandError("Date", handlerName, eText, eNumber, eFrom, eTo)
lns2.scpt
to _epochDate() -- 1 January 2001, 00:00:00 GMT, i.e. Cocoa epoch
lns2.scpt
return (current application's NSDate's dateWithTimeIntervalSinceReferenceDate:0)
lns2.scpt
end _epochDate
lns2.scpt
property _months : {January, February, March, April, May, June, July, August, September, October, November, December}
lns2.scpt
property _weekdays : {Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday}
lns2.scpt
property _ISO8601Format : "yyyy-MM-dd'T'HH:mm:ssZZ" -- canonical date format
lns2.scpt
to month names
lns2.scpt
return items of _months -- shallow copy list before returning it to ensure any changes the user might make to the returned list won't affect the original
lns2.scpt
end month names
lns2.scpt
to weekday names
lns2.scpt
return items of _weekdays -- ditto
lns2.scpt
end weekday names
lns2.scpt
to _gregorianCalendar()
lns2.scpt
return current application's NSCalendar's calendarWithIdentifier:(current application's NSGregorianCalendar)
lns2.scpt