text
stringlengths
0
15.7k
source
stringlengths
6
112
set {theXMLDoc, theError} to current application's NSXMLDocument's alloc()'s initWithData:pageHTML options:(current application's NSXMLDocumentTidyHTML) |error|:(reference)
lns1.scpt
if theXMLDoc = missing value then error (theError's localizedDescription() as text)
lns1.scpt
set {theMatches, theError} to (theXMLDoc's nodesForXPath:"//span" |error|:(reference))
lns1.scpt
if theMatches = missing value then error (theError's localizedDescription() as text)
lns1.scpt
set end of theResult to aMatch's stringValue() as text
lns1.scpt
property NSFontManager : a reference to current application's NSFontManager
lns1.scpt
property NSMutableAttributedString : a reference to current application's NSMutableAttributedString
lns1.scpt
property NSForegroundColorAttributeName : a reference to current application's NSForegroundColorAttributeName
lns1.scpt
property NSBoldFontMask : a reference to current application's NSBoldFontMask
lns1.scpt
set theString to "The quick brown fox jumped over the lazy dog"
lns1.scpt
set theBoldWords to {"fox", "dog"}
lns1.scpt
set theRedWords to {"jumped"}
lns1.scpt
set theGreenWords to {"quick", "lazy"}
lns1.scpt
set theBlackColor to NSColor's blackColor()
lns1.scpt
set theRedColor to NSColor's redColor()
lns1.scpt
set theGreenColor to NSColor's greenColor()
lns1.scpt
set theFont to NSFont's fontWithName:"Helvetica" |size|:30
lns1.scpt
set theBoldFont to NSFontManager's sharedFontManager()'s convertFont:theFont toHaveTrait:NSBoldFontMask
lns1.scpt
set theDict to NSDictionary's dictionaryWithObjects:{theBlackColor, theFont} forKeys:{NSForegroundColorAttributeName, NSFontAttributeName}
lns1.scpt
set theATS to NSMutableAttributedString's alloc()'s initWithString:theString attributes:theDict
lns1.scpt
repeat with aWord in theBoldWords
lns1.scpt
set range to (theATS's |string|()'s rangeOfString:aWord)
lns1.scpt
(theATS's addAttribute:NSFontAttributeName value:theBoldFont range:range)
lns1.scpt
repeat with aWord in theRedWords
lns1.scpt
(theATS's addAttribute:NSForegroundColorAttributeName value:theRedColor range:range)
lns1.scpt
repeat with aWord in theGreenWords
lns1.scpt
(theATS's addAttribute:NSForegroundColorAttributeName value:theGreenColor range:range)
lns1.scpt
theATS -- lets look at it
lns1.scpt
property NSJSONWritingPrettyPrinted : a reference to 1
lns1.scpt
set theData to {|menu|:¬ {|id|:"file", value:"File", popup:¬ {menuitem:{¬ {value:"New", onclick:"CreateNewDoc()"}, ¬
lns1.scpt
{value:"Open", onclick:"OpenDoc()"}, ¬
lns1.scpt
{value:"Close", onclick:"CloseDoc()"}}}}}
lns1.scpt
set theJSONData to NSJSONSerialization's dataWithJSONObject:theData options:NSJSONWritingPrettyPrinted |error|:(missing value)
lns1.scpt
theJSONData's writeToFile:(theFile's POSIX path) atomically:false
lns1.scpt
set {json, e} to ca's NSJSONSerialization's dataWithJSONObject:x options:1 |error|:(reference)
lns1.scpt
e's localizedDescription() as text
lns1.scpt
set theJSONData to NSData's dataWithContentsOfFile:(theFile's POSIX path)
lns1.scpt
theJSON as record
lns1.scpt
--> { -- |menu|:{ -- |id|:"file", -- value:"File", -- popup:{ -- menuitem:{ -- { -- value:"New", -- onclick:"CreateNewDoc()" -- },
lns1.scpt
-- { -- value:"Open", -- onclick:"OpenDoc()" -- },
lns1.scpt
-- { -- value:"Close", -- onclick:"CloseDoc()" -- }
lns1.scpt
property NSCapsLockMask : a reference to 65536
lns1.scpt
property NSOptionKeyMask : a reference to 524288
lns1.scpt
property NSFunctionKeyMask : a reference to 8388608
lns1.scpt
on KeyPressed(KeyName)
lns1.scpt
if KeyName = "caps lock" then
lns1.scpt
set TheMask to NSCapsLockMask
lns1.scpt
else if KeyName = "shift" then
lns1.scpt
set TheMask to NSShiftKeyMask
lns1.scpt
else if KeyName = "control" then
lns1.scpt
set TheMask to NSControlKeyMask
lns1.scpt
else if KeyName = "option" then
lns1.scpt
set TheMask to NSOptionKeyMask
lns1.scpt
else if KeyName = "command" then
lns1.scpt
set TheMask to NSCommandKeyMask
lns1.scpt
else if KeyName = "function" then
lns1.scpt
set TheMask to NSFunctionKeyMask
lns1.scpt
set MFlags to NSEvent's modifierFlags() as integer
lns1.scpt
if ((MFlags div TheMask) mod 2) = 0 then
lns1.scpt
end KeyPressed
lns1.scpt
on TheModifiersKeysPressedDown()
lns1.scpt
set TheKeys to {}
lns1.scpt
set KeyFlags to NSEvent's modifierFlags() as integer
lns1.scpt
if ((KeyFlags div NSCapsLockMask) mod 2) is not 0 then
lns1.scpt
set TheKeys to TheKeys & {"caps lock"}
lns1.scpt
if ((KeyFlags div NSShiftKeyMask) mod 2) is not 0 then
lns1.scpt
set TheKeys to TheKeys & {"shift"}
lns1.scpt
if ((KeyFlags div NSControlKeyMask) mod 2) is not 0 then
lns1.scpt
set TheKeys to TheKeys & {"control"}
lns1.scpt
if ((KeyFlags div NSOptionKeyMask) mod 2) is not 0 then
lns1.scpt
set TheKeys to TheKeys & {"option"}
lns1.scpt
if ((KeyFlags div NSCommandKeyMask) mod 2) is not 0 then
lns1.scpt
set TheKeys to TheKeys & {"command"}
lns1.scpt
if ((KeyFlags div NSFunctionKeyMask) mod 2) is not 0 then
lns1.scpt
set TheKeys to TheKeys & {"function"}
lns1.scpt
return TheKeys
lns1.scpt
end TheModifiersKeysPressedDown
lns1.scpt
KeyPressed("caps lock") --> true
lns1.scpt
KeyPressed("option") --> true
lns1.scpt
KeyPressed("option") --> false
lns1.scpt
TheModifiersKeysPressedDown() --> {"caps lock", "shift", "control", "option", "command", "function"}
lns1.scpt
TheModifiersKeysPressedDown() --> {}
lns1.scpt
set QuitLoop to false
lns1.scpt
repeat while (not QuitLoop)
lns1.scpt
if KeyPressed("shift") then
lns1.scpt
set QuitLoop to true
lns1.scpt
set sound volume to 40
lns1.scpt
set EQ enabled to true
lns1.scpt
key code 11 using command down
lns1.scpt
key code 5 using {command down, shift down}
lns1.scpt
key code 34 using command down
lns1.scpt
key code 38 using command down
lns1.scpt
key code 37 using command down
lns1.scpt
key code 15 using {command down, shift down}
lns1.scpt
key code 6 using {command down, control down}
lns1.scpt
key code 51 using command down
lns1.scpt
key code 51 using option down
lns1.scpt
key code 3 using {command down, option down}
lns1.scpt
key code 45 using {command down, shift down}
lns1.scpt
key code 45 using {command down, option down}
lns1.scpt